[Bug c++/83167] New: decltype((x)) inside lambda is considered odr-use if x is not a reference
deaeod at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sun Nov 26 11:35:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83167
Bug ID: 83167
Summary: decltype((x)) inside lambda is considered odr-use if x
is not a reference
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: deaeod at gmail dot com
Target Milestone: ---
https://godbolt.org/g/NmA3ZP
#include <type_traits>
int main() {
int x = 1;
int&& y = static_cast<int&&>(x);
auto A = []{ static_assert(std::is_same_v<decltype((x)), int&>); };
auto B = [=]{ static_assert(std::is_same_v<decltype((x)), int&>); };
auto C = []{ static_assert(std::is_same_v<decltype((y)), int&>); };
auto D = [=]{ static_assert(std::is_same_v<decltype((y)), int&>); };
}
I expected this to compile cleanly, but static asserts A and B fail under g++.
A fails because x wasnt captured and B fails because the deduced type is const
int&.
Here is how i would argue for my expectation:
http://eel.is/c++draft/expr.prim.lambda#capture-11.sentence-3
-- "An id-expression that is not an odr-use refers to the original entity,
never to a member of the closure type."
http://eel.is/c++draft/basic.def.odr#def:potentially_evaluated
-- "An expression is potentially evaluated unless it is an unevaluated
operand or a subexpression thereof."
http://eel.is/c++draft/basic.def.odr#def:odr-used
-- "A variable x whose name appears as a potentially-evaluated expression
ex is odr-used by ex unless [...]"
http://eel.is/c++draft/dcl.type.simple#4.sentence-3
-- "The operand of the decltype specifier is an unevaluated operand."
More information about the Gcc-bugs
mailing list