[Bug c++/58848] constexpr function allows throw

2016-05-13 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58848

Martin Sebor  changed:

   What|Removed |Added

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

--- Comment #4 from Martin Sebor  ---
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 
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);
$

[Bug c++/58848] constexpr function allows throw

2013-10-30 Thread redi at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58848

--- Comment #3 from Jonathan Wakely  ---
The initializer for ReferenceElement::v calls the function in
a constant expression, but G++ doesn't diagnose it unless you instantiate that
member.

You get an error if you do:

int main() {
  return ReferenceElement::v;
}


[Bug c++/58848] constexpr function allows throw

2013-10-23 Thread daniel.kruegler at googlemail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58848

Daniel Krügler  changed:

   What|Removed |Added

 CC||daniel.kruegler@googlemail.
   ||com

--- Comment #2 from Daniel Krügler  ---
I cannot follow your argumentation for constexp_error.cpp: The main function
invokes

ReferenceElement::numSubEntities(7)

This function is declared as

  static inline unsigned numSubEntities(int codim) {
return typeTraits_::numSubEntities(codim);
  }

Note in particular that this is *not* a constexpr function. Now it delegates to
typeTraits_::numSubEntities, which is defined as:

  static constexpr unsigned numSubEntities(int codim) {
return codim==0 ? 11 : throw 20;
  }

This is a constexpr function, but it is not called with constant arguments that
require the evaluation of this function in a constexpr context. Thus, throwing
an exception is valid here.

So what is the problem?

[Bug c++/58848] constexpr function allows throw

2013-10-22 Thread mib.bugzilla at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58848

--- Comment #1 from mib.bugzilla at gmail dot com ---
Created attachment 31073
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31073&action=edit
simpler test case gets compilation error (good)

both test cases should get a compilation error because of the throw.