public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53473] New: [C++11] static constexpr noexcept cannot be specialized
@ 2012-05-24 13:40 kretz at kde dot org
  2012-05-25  7:00 ` [Bug c++/53473] " daniel.kruegler at googlemail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: kretz at kde dot org @ 2012-05-24 13:40 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53473

             Bug #: 53473
           Summary: [C++11] static constexpr noexcept cannot be
                    specialized
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: kretz@kde.org


The following testcase does not compile.

template<typename T> struct A
{
    static constexpr T foo() noexcept { return 0; }
};

template<> constexpr int A<int>::foo() noexcept { return 0; }

This would be a common pattern to specialize functions of std::numeric_limits,
but it's currently only possible to specialize the whole numeric_limits class.


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

* [Bug c++/53473] [C++11] static constexpr noexcept cannot be specialized
  2012-05-24 13:40 [Bug c++/53473] New: [C++11] static constexpr noexcept cannot be specialized kretz at kde dot org
@ 2012-05-25  7:00 ` daniel.kruegler at googlemail dot com
  2012-05-25  9:07 ` kretz at kde dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-05-25  7:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53473

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-05-25 06:56:06 UTC ---
This looks indeed like an odd compiler error and one really needs all three
specifiers static, constexpr, and *any* exception-specification to produce the
problem. For completeness the error is:

"7|error: declaration of 'static constexpr T A<T>::foo() [with T = int]' has a
different exception specifier|
3|error: from previous declaration 'static constexpr T A<T>::foo() noexcept
(true) [with T = int]'
"


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

* [Bug c++/53473] [C++11] static constexpr noexcept cannot be specialized
  2012-05-24 13:40 [Bug c++/53473] New: [C++11] static constexpr noexcept cannot be specialized kretz at kde dot org
  2012-05-25  7:00 ` [Bug c++/53473] " daniel.kruegler at googlemail dot com
@ 2012-05-25  9:07 ` kretz at kde dot org
  2012-05-25  9:24 ` daniel.kruegler at googlemail dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: kretz at kde dot org @ 2012-05-25  9:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53473

--- Comment #2 from Matthias Kretz <kretz at kde dot org> 2012-05-25 08:53:36 UTC ---
Does the standard allow exceptions in constexpr? A throw is not exactly a
return statement, but according to the rule "constexpr function shall satisfy
[...] exactly one return statement" I'd expect a constexpr function can never
throw anyway. Thus the noexcept itself seems to make no sense in the first
place.


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

* [Bug c++/53473] [C++11] static constexpr noexcept cannot be specialized
  2012-05-24 13:40 [Bug c++/53473] New: [C++11] static constexpr noexcept cannot be specialized kretz at kde dot org
  2012-05-25  7:00 ` [Bug c++/53473] " daniel.kruegler at googlemail dot com
  2012-05-25  9:07 ` kretz at kde dot org
@ 2012-05-25  9:24 ` daniel.kruegler at googlemail dot com
  2012-05-25  9:59 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-05-25  9:24 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53473

--- Comment #3 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-05-25 09:07:20 UTC ---
(In reply to comment #2)
> Does the standard allow exceptions in constexpr? A throw is not exactly a
> return statement, but according to the rule "constexpr function shall satisfy
> [...] exactly one return statement" I'd expect a constexpr function can never
> throw anyway. Thus the noexcept itself seems to make no sense in the first
> place.

No, both concepts of constant expressions and exception-specifications are
independent decisions. The following is a perfectly valid constexpr function:

#include <stdexcept>

constexpr int validating_abs(int val) noexcept(false)
{ return val < 0 ? throw std::runtime_error("negative") : val; }

int main()
{
  constexpr int v1 = validating_abs(1); // OK
  constexpr int v2 = validating_abs(-1); // Error
  int v = -1;
  try {
    int v3 = validating_abs(v); // OK, runtime validation
  } catch (std::runtime_error&) {}
}

It is just a fact, that the "effective expression" is relevant when we consider
constant expressions and throw expressions, like for v2. But constexpr
functions can also be called in non-constant contexts - like for v3 - where
this restriction does not exist.


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

* [Bug c++/53473] [C++11] static constexpr noexcept cannot be specialized
  2012-05-24 13:40 [Bug c++/53473] New: [C++11] static constexpr noexcept cannot be specialized kretz at kde dot org
                   ` (2 preceding siblings ...)
  2012-05-25  9:24 ` daniel.kruegler at googlemail dot com
@ 2012-05-25  9:59 ` redi at gcc dot gnu.org
  2013-11-18 15:02 ` paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2012-05-25  9:59 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53473

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-05-25 09:44:45 UTC ---
Yes, odd indeed.

Oddly, Clang barfs on the testcase with a similar error:

t.cc:6:34: error: conflicting types for 'foo'


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

* [Bug c++/53473] [C++11] static constexpr noexcept cannot be specialized
  2012-05-24 13:40 [Bug c++/53473] New: [C++11] static constexpr noexcept cannot be specialized kretz at kde dot org
                   ` (3 preceding siblings ...)
  2012-05-25  9:59 ` redi at gcc dot gnu.org
@ 2013-11-18 15:02 ` paolo.carlini at oracle dot com
  2013-11-18 15:27 ` paolo.carlini at oracle dot com
  2013-11-18 15:28 ` paolo at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-11-18 15:02 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53473

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |4.8.1, 4.9.0

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
This is fixed in 4.8.1 and mainline. I'm adding the testcase and closing the
bug.


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

* [Bug c++/53473] [C++11] static constexpr noexcept cannot be specialized
  2012-05-24 13:40 [Bug c++/53473] New: [C++11] static constexpr noexcept cannot be specialized kretz at kde dot org
                   ` (4 preceding siblings ...)
  2013-11-18 15:02 ` paolo.carlini at oracle dot com
@ 2013-11-18 15:27 ` paolo.carlini at oracle dot com
  2013-11-18 15:28 ` paolo at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-11-18 15:27 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53473

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |4.8.1

--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Done.


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

* [Bug c++/53473] [C++11] static constexpr noexcept cannot be specialized
  2012-05-24 13:40 [Bug c++/53473] New: [C++11] static constexpr noexcept cannot be specialized kretz at kde dot org
                   ` (5 preceding siblings ...)
  2013-11-18 15:27 ` paolo.carlini at oracle dot com
@ 2013-11-18 15:28 ` paolo at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: paolo at gcc dot gnu.org @ 2013-11-18 15:28 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53473

--- Comment #6 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Mon Nov 18 15:26:45 2013
New Revision: 204967

URL: http://gcc.gnu.org/viewcvs?rev=204967&root=gcc&view=rev
Log:
2013-11-18  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/53473
    * g++.dg/cpp0x/constexpr-noexcept7.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-noexcept7.C
Modified:
    trunk/gcc/testsuite/ChangeLog


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

end of thread, other threads:[~2013-11-18 15:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-24 13:40 [Bug c++/53473] New: [C++11] static constexpr noexcept cannot be specialized kretz at kde dot org
2012-05-25  7:00 ` [Bug c++/53473] " daniel.kruegler at googlemail dot com
2012-05-25  9:07 ` kretz at kde dot org
2012-05-25  9:24 ` daniel.kruegler at googlemail dot com
2012-05-25  9:59 ` redi at gcc dot gnu.org
2013-11-18 15:02 ` paolo.carlini at oracle dot com
2013-11-18 15:27 ` paolo.carlini at oracle dot com
2013-11-18 15:28 ` paolo 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).