Bug 48945 - [C++0x] static constexpr member function cannot be defined out-of class
[C++0x] static constexpr member function cannot be defined out-of class
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: c++
4.7.0
: P3 normal
: 4.6.1
Assigned To: Jason Merrill
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-05-10 09:59 UTC by Daniel Krügler
Modified: 2011-05-25 01:15 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-05-20 22:17:15


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Krügler 2011-05-10 09:59:30 UTC
gcc 4.7.0 20110507 (experimental) in C++0x mode rejects the following code:

//---
struct A {
  static constexpr bool is();
};

constexpr bool A::is() { return true; }
//---

"error: static member function 'constexpr bool A::is() const' declared with type qualifiers"

According to 7.1.5 [dcl.constexpr] p. 1

"If any declaration of a function or function template has constexpr specifier, then all its declarations shall contain the constexpr specifier."

the constexpr specifier is required as part of the function definition and the code should be accepted. It seems that gcc incorrectly attempts to reapply a const-qualifier to the static member.
Comment 1 Jason Merrill 2011-05-21 22:01:40 UTC
Author: jason
Date: Sat May 21 22:01:38 2011
New Revision: 174006

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174006
Log:
	PR c++/48945
	* decl.c (revert_static_member_fn): Ignore const on constexpr fn.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-static7.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 2 Jason Merrill 2011-05-21 22:01:48 UTC
Author: jason
Date: Sat May 21 22:01:45 2011
New Revision: 174007

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174007
Log:
	PR c++/48945
	* decl.c (grokdeclarator): Don't add set const function-cv-qual
	for constexpr fns to memfn_quals, just add it to the type.
	(revert_static_member_fn): Don't complain about quals.
	(check_static_quals): New.
	(grokfndecl): Call it.
	(start_preparsed_function): Don't call revert_static_member_fn.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-static7.C
Comment 3 Jason Merrill 2011-05-22 00:29:06 UTC
Author: jason
Date: Sun May 22 00:29:03 2011
New Revision: 174023

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174023
Log:
	PR c++/48945
	* decl.c (revert_static_member_fn): Ignore const on constexpr fn.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/constexpr-static7.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/decl.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 4 Jason Merrill 2011-05-25 01:15:31 UTC
Fixed for 4.6.1.