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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |msebor at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
The first test case can be reduced to the one below which GCC also accepts. 
But based on my reading of the standard, I think the test case is valid because
the definition (including the initialization) of A<0>::v is never instantiated.
 (See the quotes from the C++ standard below for reference.)

The second test case requires a diagnostic because the constexpr function
called in a constexpr context with an argument that would cause the throw
expression to be evaluated.

I'm resolving this as Invalid (see also bug 70820 for a similar example.)

Quoting from temp.inst:

-1- The implicit instantiation of a class template specialization causes the
implicit instantiation of the declarations, but not of the definitions, ... of
... static data members.

-11-  An implementation shall not implicitly instantiate ... a static data
member of a class template that does not require instantiation.

$ cat xx.cpp && gcc -S -Wall -Wextra -Wpedantic -std=c++11 xx.cpp 
template <int>
struct A
{
  static constexpr int
  f (int i)
  {
    return i ? i : throw 0;
  }

  static const int v = f (0);
};

int i = A<0>::f (0);
$

Reply via email to