public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113266] New: GCC rejects static global variable as non type template parameter
@ 2024-01-08  8:28 jlame646 at gmail dot com
  2024-01-08 16:15 ` [Bug c++/113266] GCC rejects static global variable as non type template parameter before C++17 mode pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: jlame646 at gmail dot com @ 2024-01-08  8:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113266
           Summary: GCC rejects static global variable as non type
                    template parameter
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jlame646 at gmail dot com
  Target Milestone: ---

The following valid program is rejected by gcc but accepted by other compilers.
https://godbolt.org/z/x1eG9dhc3

```
#include <iostream>
#include <string>

template <int& N>
void printString()
{
    std::cout << N << std::endl;
}

int a;
static int b;

template void printString<a>(); //all accepts this
template void printString<b>();//only gcc rejects this


int main()
{

}
```

GCC says:
```
error: the value of 'b' is not usable in a constant expression
   14 | template void printString<b>();//only gcc rejects this
      |                           ^
<source>:11:12: note: 'int b' is not const
   11 | static int b;
      |            ^
```

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

* [Bug c++/113266] GCC rejects static global variable as non type template parameter before C++17 mode
  2024-01-08  8:28 [Bug c++/113266] New: GCC rejects static global variable as non type template parameter jlame646 at gmail dot com
@ 2024-01-08 16:15 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-08 16:15 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
      Known to fail|                            |4.7.0
   Last reconfirmed|                            |2024-01-08
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---

Confirmed, not a regression, has been an bug since the addition of the C++11
rule that allowed addresses of static variables as template arguments (back in
GCC 4.7.0).

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

end of thread, other threads:[~2024-01-08 16:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-08  8:28 [Bug c++/113266] New: GCC rejects static global variable as non type template parameter jlame646 at gmail dot com
2024-01-08 16:15 ` [Bug c++/113266] GCC rejects static global variable as non type template parameter before C++17 mode pinskia 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).