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

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