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

            Bug ID: 99901
           Summary: static const class var implemented with constexpr
                    doesn't emit symbols in C++17 mode
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tellowkrinkle at gmail dot com
  Target Milestone: ---

The following code fails to output any symbols when compiled with `-std=c++17`:

struct A {
    static const int a;
};
constexpr int A::a = 5;

Godbolt link: https://gcc.godbolt.org/z/13efnK4x4

You can run this in a way that results in a linker error with the following:

a.h:
#pragma once
struct A { static const int a; };

a.cpp:
#include "a.h"
constexpr int A::a = 0;

main.cpp:
#include "a.h"
int main() { return A::a; }

Works fine when compiled with `g++ main.cpp a.cpp`
Fails when compiled with `g++ -std=c++17 main.cpp a.cpp`

Reply via email to