public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107939] New: Rejects use of `extern const` variable in a template
@ 2022-11-30 19:32 johelegp at gmail dot com
  2022-11-30 19:35 ` [Bug c++/107939] [11/12/13 Regression] " pinskia at gcc dot gnu.org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: johelegp at gmail dot com @ 2022-11-30 19:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107939

            Bug ID: 107939
           Summary: Rejects use of `extern const` variable in a template
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: johelegp at gmail dot com
                CC: johelegp at gmail dot com
  Target Milestone: ---

See https://compiler-explorer.com/z/q3a7e7s1e.
Changing `#if 1` to `#if 0` works, so this can't be due to
> The program is ill-formed, no diagnostic required, if:
> (6.4) a hypothetical instantiation of a template immediately following its definition would be ill-formed due to a construct that does not depend on a template parameter, or
> -- https://eel.is/c++draft/temp.res.general#6.4

And since all compilers accept it as a non-template, nothing in [expr.const] is
being violated.

```C++
struct Q {
  struct P {
    const Q* p;
  };
  int n;
  constexpr P operator()(auto) const { return {this}; }
};

extern const Q q;

#if 1
template<int> constexpr auto p = q(0);
static_assert(p<0>.p == &q);
#else
constexpr auto p = q(0);
static_assert(p.p == &q);
#endif

constexpr Q q = {};
```

```
<source>:12:37: error: the value of 'q' is not usable in a constant expression
   12 | template<int> constexpr auto p = q(0);
      |                                     ^
<source>:9:16: note: 'q' was not declared 'constexpr'
    9 | extern const Q q;
      |                ^
<source>:13:22: error: non-constant condition for static assertion
   13 | static_assert(p<0>.p == &q);
      |               ~~~~~~~^~~~~
Compiler returned: 1
```

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-11-27 22:02 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-30 19:32 [Bug c++/107939] New: Rejects use of `extern const` variable in a template johelegp at gmail dot com
2022-11-30 19:35 ` [Bug c++/107939] [11/12/13 Regression] " pinskia at gcc dot gnu.org
2022-11-30 19:36 ` johelegp at gmail dot com
2022-12-01  8:04 ` rguenth at gcc dot gnu.org
2022-12-02 14:19 ` [Bug c++/107939] [11/12/13 Regression] Rejects use of `extern const` variable in a template since r11-557 jakub at gcc dot gnu.org
2023-03-02 22:48 ` mpolacek at gcc dot gnu.org
2023-03-03  0:02 ` mpolacek at gcc dot gnu.org
2023-03-03 16:35 ` mpolacek at gcc dot gnu.org
2023-03-07 15:13 ` cvs-commit at gcc dot gnu.org
2023-03-07 15:16 ` [Bug c++/107939] [11/12 " mpolacek at gcc dot gnu.org
2023-03-07 15:25 ` cvs-commit at gcc dot gnu.org
2023-03-07 15:25 ` [Bug c++/107939] [11 " mpolacek at gcc dot gnu.org
2023-11-16 14:32 ` cvs-commit at gcc dot gnu.org
2023-11-24 16:56 ` cvs-commit at gcc dot gnu.org
2023-11-27 22:02 ` cvs-commit 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).