https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116385
Bug ID: 116385 Summary: Unevaluated usage of function parameters with typeid incorrectly considered odr-use Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mital at mitalashok dot co.uk Target Milestone: --- This is the example taken from https://eel.is/c++draft/basic.def.odr#example-2 but modified to use `typeid` instead of `=` to make it a non-odr-use (as the typeid of a glvalue of a non-polymorphic type) https://godbolt.org/z/dh6P8q4fh ``` namespace std { struct type_info; } void f(int n) { [] { typeid(n); }; struct A { void f() { typeid(n); } }; void g(const std::type_info& = typeid(n)); [](const std::type_info& = typeid(n)) {}; } ``` All 4 usages have an error. <source>: In lambda function: <source>:3:15: error: 'n' is not captured 3 | [] { typeid(n); }; | ^ <source>:3:4: note: the lambda has no capture-default 3 | [] { typeid(n); }; | ^ <source>:2:12: note: 'int n' declared here 2 | void f(int n) { | ~~~~^ <source>: In member function 'void f(int)::A::f()': <source>:5:23: error: use of parameter from containing function 5 | void f() { typeid(n); } | ^ <source>:2:12: note: 'int n' declared here 2 | void f(int n) { | ~~~~^ <source>: In function 'void f(int)': <source>:7:41: error: parameter 'n' may not appear in this context 7 | void g(const std::type_info& = typeid(n)); | ^ <source>:8:37: error: parameter 'n' may not appear in this context 8 | [](const std::type_info& = typeid(n)) {}; | ^ Unevaluated usages with `sizeof` (<https://godbolt.org/z/W81ajKsbn>) do not error