public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/116385] New: Unevaluated usage of function parameters with typeid incorrectly considered odr-use @ 2024-08-15 15:47 mital at mitalashok dot co.uk 2024-08-15 15:51 ` [Bug c++/116385] " pinskia at gcc dot gnu.org ` (3 more replies) 0 siblings, 4 replies; 5+ messages in thread From: mital at mitalashok dot co.uk @ 2024-08-15 15:47 UTC (permalink / raw) To: gcc-bugs 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/116385] Unevaluated usage of function parameters with typeid incorrectly considered odr-use 2024-08-15 15:47 [Bug c++/116385] New: Unevaluated usage of function parameters with typeid incorrectly considered odr-use mital at mitalashok dot co.uk @ 2024-08-15 15:51 ` pinskia at gcc dot gnu.org 2024-08-15 15:53 ` pinskia at gcc dot gnu.org ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-08-15 15:51 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116385 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- MSVC rejects the default argument usage: <source>(8): error C2587: 'n': illegal use of local variable as default parameter <source>(3): note: see declaration of 'n' <source>(9): error C2587: 'n': illegal use of local variable as default parameter <source>(3): note: see declaration of 'n' ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/116385] Unevaluated usage of function parameters with typeid incorrectly considered odr-use 2024-08-15 15:47 [Bug c++/116385] New: Unevaluated usage of function parameters with typeid incorrectly considered odr-use mital at mitalashok dot co.uk 2024-08-15 15:51 ` [Bug c++/116385] " pinskia at gcc dot gnu.org @ 2024-08-15 15:53 ` pinskia at gcc dot gnu.org 2024-08-15 16:06 ` mpolacek at gcc dot gnu.org 2024-08-15 16:28 ` mpolacek at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-08-15 15:53 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116385 --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Andrew Pinski from comment #1) > MSVC rejects the default argument usage: > > <source>(8): error C2587: 'n': illegal use of local variable as default > parameter > <source>(3): note: see declaration of 'n' > <source>(9): error C2587: 'n': illegal use of local variable as default > parameter > <source>(3): note: see declaration of 'n' And lambda usage: <source>(4): error C3493: 'n' cannot be implicitly captured because no default capture mode has been specified But accepts the usage in local class. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/116385] Unevaluated usage of function parameters with typeid incorrectly considered odr-use 2024-08-15 15:47 [Bug c++/116385] New: Unevaluated usage of function parameters with typeid incorrectly considered odr-use mital at mitalashok dot co.uk 2024-08-15 15:51 ` [Bug c++/116385] " pinskia at gcc dot gnu.org 2024-08-15 15:53 ` pinskia at gcc dot gnu.org @ 2024-08-15 16:06 ` mpolacek at gcc dot gnu.org 2024-08-15 16:28 ` mpolacek at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: mpolacek at gcc dot gnu.org @ 2024-08-15 16:06 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116385 Marek Polacek <mpolacek at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |mpolacek at gcc dot gnu.org --- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> --- It appears that (part of) the problem is that cp_unevaluated_operand is not properly set when we reach process_outer_var_ref. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/116385] Unevaluated usage of function parameters with typeid incorrectly considered odr-use 2024-08-15 15:47 [Bug c++/116385] New: Unevaluated usage of function parameters with typeid incorrectly considered odr-use mital at mitalashok dot co.uk ` (2 preceding siblings ...) 2024-08-15 16:06 ` mpolacek at gcc dot gnu.org @ 2024-08-15 16:28 ` mpolacek at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: mpolacek at gcc dot gnu.org @ 2024-08-15 16:28 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116385 --- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> --- In fact I see no RID_TYPEID cp_unevaluated so that's probably the problem. Even C++11 said "The expression is an unevaluated operand." Probably a dup of bug 68604. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-08-15 16:28 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-08-15 15:47 [Bug c++/116385] New: Unevaluated usage of function parameters with typeid incorrectly considered odr-use mital at mitalashok dot co.uk 2024-08-15 15:51 ` [Bug c++/116385] " pinskia at gcc dot gnu.org 2024-08-15 15:53 ` pinskia at gcc dot gnu.org 2024-08-15 16:06 ` mpolacek at gcc dot gnu.org 2024-08-15 16:28 ` mpolacek at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).