g++ 7.3.0 & 8.2.0: weird std::string_view behavior when using in-line if-else

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

today some code of mine using std::string_view broke out of seemingly
nowhere; the following program is a minimal recreation of the odd
behavior I'm seeing:

	$ cat string_view_test.cpp
	#include <string_view>
	#include <string>
	#include <iostream>

	int main()
	{
		std::string str = "Victory of Eagles";
		std::string_view sv = true ? str : "";
		std::cout << sv << "\n";
	}

The above program, when compiled with g++ v7.3.0 or v8.2.0 via

	$ g++ -std=c++17 string_view_test.cpp

prints "of Eagles" when run where "Victory of Eagles" is expected.
Omitting the in-lined if-else, and instead just

	std::string_view sv = str;

solves the issue, but I have no idea why. What's up with this behavior?

Cheers.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux