[Bug c++/77875] C++ core issue 1288
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77875 Andrew Pinski changed: What|Removed |Added CC||vanyacpp at gmail dot com --- Comment #6 from Andrew Pinski --- *** Bug 100039 has been marked as a duplicate of this bug. ***
[Bug c++/77875] C++ core issue 1288
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77875 --- Comment #5 from Jonathan Wakely --- Yes, probably, but it doesn't seem useful for T{i} to do anything except bind a reference of type T to i. Issue 1521 seems to be a problem with the wording, such that it doesn't apply to references, but I doubt it will be resolved by saying that T{i} does anything surprising. But maybe I'm missing something.
[Bug c++/77875] C++ core issue 1288
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77875 --- Comment #4 from Marek Polacek --- Doesn't this depend on the resolution of Core 1521 (still "drafting"), dealing with T{expr} where T is a reference type? Which is what this PR is about: void f () { int i = 42; using T = int&; T t = T{i}; }
[Bug c++/77875] C++ core issue 1288
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77875 --- Comment #3 from Lénárd Szolnoki --- A more worrisome example presumably for this same bug, it's a miscompilation: template decltype(auto) as_const(T& t) { using const_ref = const T&; return const_ref{t}; } int main() { int i = 42; return as_const(i); } $ g++ -std=c++17 -O0 -fsanitize=undefined -Wall -pedantic main.cpp && ./a.out main.cpp: In instantiation of 'decltype(auto) as_const(T&) [with T = int]': main.cpp:9:22: required from here main.cpp:4:23: warning: returning reference to temporary [-Wreturn-local-addr] return const_ref{t}; ^ main.cpp:4:23: runtime error: reference binding to null pointer of type 'const int' main.cpp:9:22: runtime error: load of null pointer of type 'const int' bash: line 7: 802 Segmentation fault (core dumped) ./a.out An UB is added where should be none.
[Bug c++/77875] C++ core issue 1288
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77875 Jonathan Wakely changed: What|Removed |Added Keywords||rejects-valid Status|UNCONFIRMED |NEW Last reconfirmed||2019-03-27 Ever confirmed|0 |1 --- Comment #2 from Jonathan Wakely --- From PR 89857: gcc doesn't compile the following well-formed program: void foo () { using T = int&; int i{}; T{i}; } $ g++ -std=c++17 -c gcc_bug2.cpp gcc_bug2.cpp: In function ‘void foo()’: gcc_bug2.cpp:4:8: error: invalid cast of an rvalue expression of type ‘int’ to type ‘T’ {aka ‘int&’} T{i}; Quoting from the standard draft: http://eel.is/c++draft/dcl.init.list#3.9 Otherwise, if the initializer list has a single element of type E and either T is not a reference type or its referenced type is reference-related to E, the object or reference is initialized from that element (by copy-initialization for copy-list-initialization, or by direct-initialization for direct-list-initialization); if a narrowing conversion (see below) is required to convert the element to T, the program is ill-formed. According to the error, it looks like gcc skips this and tries to apply the next rule: Otherwise, if T is a reference type, a prvalue of the type referenced by T is generated. The prvalue initializes its result object by copy-list-initialization. The prvalue is then used to direct-initialize the reference. [ Note: As usual, the binding will fail and the program is ill-formed if the reference type is an lvalue reference to a non-const type. — end note ] Note: The current behavior was originally a defect in the C++11 standard that was corrected in CWG1288. http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#1288
[Bug c++/77875] C++ core issue 1288
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77875 Jonathan Wakely changed: What|Removed |Added CC||leni536 at gmail dot com --- Comment #1 from Jonathan Wakely --- *** Bug 89857 has been marked as a duplicate of this bug. ***