Bug 56871 - [c++11] Specialization of constexpr Templated Function
Summary: [c++11] Specialization of constexpr Templated Function
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.9.0
Assignee: Paolo Carlini
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2013-04-08 05:37 UTC by David Narváez
Modified: 2013-04-08 18:10 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-04-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Narváez 2013-04-08 05:37:33 UTC
Consider the code below

template<typename T> constexpr int foo(T) { return 0; };
template<> int foo(int) { return 1; }

Compiling this code with g++-4.8.0 -Wall -c -std=c++0x bug.cpp throws the following error:

bug.cpp:2:23: error: redeclaration ‘constexpr int foo(T) [with T = int]’ differs in ‘constexpr’
 template<> int foo(int) { return 1; }
                       ^
bug.cpp:1:36: error: from previous declaration ‘constexpr int foo(T) [with T = int]’
 template<typename T> constexpr int foo(T) { return 0; };

Yet, the C++ standard (section 7.1.5) says that an explicit specialization can differ from the template declaration with respect to the constexpr specifier.
Comment 1 Paolo Carlini 2013-04-08 09:33:39 UTC
Seems easy.
Comment 2 Paolo Carlini 2013-04-08 18:10:20 UTC
Fixed for 4.9.0.