Skip to content

decltype((x)) inside lambda is considered odr-use if x is captured #34771

Closed
@llvmbot

Description

@llvmbot
Bugzilla Link 35423
Resolution INVALID
Resolved on Dec 16, 2017 08:59
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @dwblaikie,@DougGregor,@zygoloid

Extended Description

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 B and D fail under clang.

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."

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++invalidResolved as invalid, i.e. not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions