This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/47774] [C++0x] constexpr specifier on ctor not ignored when template instantiation causes ctor to not satify constexpr requirements
- From: "dev.lists at jessamine dot co.uk" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 1 Mar 2011 15:34:50 +0000
- Subject: [Bug c++/47774] [C++0x] constexpr specifier on ctor not ignored when template instantiation causes ctor to not satify constexpr requirements
- Auto-submitted: auto-generated
- References: <bug-47774-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47774
--- Comment #7 from Adam Butcher <dev.lists at jessamine dot co.uk> 2011-03-01 15:34:40 UTC ---
(In reply to comment #6)
> Yep, this is fixed too.
>
> *** This bug has been marked as a duplicate of bug 46472 ***
>
The attached program demonstrated instances of the bug with various member
types. It still fails on two cases when using array members. I don't think
they are errors. Running
sh constexpr-ctor-templ.cpp
with 4.6.0 20110301 now yields the following (output compressed for legibility
[snip] = -c constexpr-ctor-templ.cpp -std=c++0x).
--------------------------------------------
+ g++ [snip] -DPLAIN_T -DUSE_SYNTHESIZED_X_CTOR
+ g++ [snip] -DPLAIN_T -DGIVE_X_EXPLICIT_CONSTEXPR_CTOR
+ g++ [snip] -DPLAIN_T -DGIVE_X_EXPLICIT_NONCONST_CTOR
+ g++ [snip] -DPLAIN_T_ARRAY -DUSE_SYNTHESIZED_X_CTOR
--------------------------------------------
+ g++ [snip] -DPLAIN_T_ARRAY -DGIVE_X_EXPLICIT_CONSTEXPR_CTOR
constexpr-ctor-templ.cpp: In constructor âconstexpr X<T>::X() [with T =
ncbool]â:
constexpr-ctor-templ.cpp:148:14: instantiated from here
constexpr-ctor-templ.cpp:103:24: error: âncbool::ncbool(bool)â is not
âconstexprâ
--------------------------------------------
+ g++ [snip] -DPLAIN_T_ARRAY -DGIVE_X_EXPLICIT_NONCONST_CTOR
+ g++ [snip] -DFLAG_T -DUSE_SYNTHESIZED_X_CTOR
+ g++ [snip] -DFLAG_T -DGIVE_X_EXPLICIT_CONSTEXPR_CTOR
+ g++ [snip] -DFLAG_T -DGIVE_X_EXPLICIT_NONCONST_CTOR
+ g++ [snip] -DFLAG_T_ARRAY -DUSE_SYNTHESIZED_X_CTOR
--------------------------------------------
+ g++ [snip] -DFLAG_T_ARRAY -DGIVE_X_EXPLICIT_CONSTEXPR_CTOR
constexpr-ctor-templ.cpp: In constructor âconstexpr X<T>::X() [with T =
ncbool]â:
constexpr-ctor-templ.cpp:148:14: instantiated from here
constexpr-ctor-templ.cpp:103:24: error: âconstexpr flag<BoolType>::flag(bool)
[with BoolType = ncbool]â is not âconstexprâ
--------------------------------------------
+ g++ [snip] -DFLAG_T_ARRAY -DGIVE_X_EXPLICIT_NONCONST_CTOR
--------------------------------------------
Failed 2
The failing invocations occur when an array of a type that cannot be used to
construct compile-time constants is used as a member of X when X is given a
constexpr constructor. With the new compiler, the result comments become:
--- constexpr-ctor-templ.cpp 2011-03-01 14:57:22.000000000 +0000
+++ constexpr-ctor-templ.cpp 2011-03-01 14:58:55.000000000 +0000
@@ -113,11 +113,11 @@
#if PLAIN_T
T mem; // doesn't fail in any mode
#elif FLAG_T
- flag<T> mem; // fails only with synthesized ctor
+ flag<T> mem; // doesn't fail in any mode now
#elif PLAIN_T_ARRAY
T mem[7]; // fails only with GIVE_X_EXPLICIT_CONSTEXPR_CTOR
#elif FLAG_T_ARRAY
- flag<T> mem[7]; // fails unless GIVE_X_EXPLICIT_NONCONST_CTOR
+ flag<T> mem[7]; // fails only with GIVE_X_EXPLICIT_CONSTEXPR_CTOR
#endif
};
I.e. The plain array member still fails as it did before and the flag<T> array
member now fails in the same way as the plain array member (which is a change
from how it failed before).
Since the failures are now purely array related, a simplified program with no
macro configuration that reproduces the problem is:
struct ncbool
{
ncbool(bool b = false) : b(b) {}
bool b;
};
template <typename BoolType>
struct flag
{
constexpr flag(BoolType b = false) : b(b) {}
BoolType b;
};
template <typename T>
struct array
{
constexpr array() : mem() {}
T mem[7];
};
int main(int argc, char**)
{
// The following are not declared constexpr
// so shouldn't result in constexpr errors.
array<ncbool> array_of_plain_ncbool;
array<flag<ncbool>> array_of_flag_ncbool;
}