Hi,
this is a relatively old bug already analyzed by Martin last year. He
also proposed a patch:
https://gcc.gnu.org/ml/gcc-patches/2016-03/msg00593.html
After a short exchange Jason proposed a different approach based on
simply completing the involved vars:
https://gcc.gnu.org/ml/gcc-patches/2016-03/msg01420.html
Having verified that Martin wasn't actively working on the bug, I
decided to try a very straightforward implementation of Jason's
suggestion - see the attached, tested x86_64-linux - which appears to
work fine as-is. Naturally, one could imagine restricting/enlarging the
set of decls to complete: some choices don't seem good, like extending
to non-constepr vars too (the corresponding snippet is ill formed anyway
due to the initialization). I didn't try to test all the possible
variants...
Thanks, Paolo.
///////////////////
/cp
2017-09-26 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/65579
* decl.c (grokdeclarator): Before calling cp_apply_type_quals_to_decl
on constexpr VAR_DECLs complete their type.
/testsuite
2017-09-26 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/65579
* g++.dg/cpp0x/constexpr-template11.C: New.
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 253134)
+++ cp/decl.c (working copy)
@@ -12348,7 +12348,11 @@ grokdeclarator (const cp_declarator *declarator,
/* Set constexpr flag on vars (functions got it in grokfndecl). */
if (constexpr_p && VAR_P (decl))
- DECL_DECLARED_CONSTEXPR_P (decl) = true;
+ {
+ DECL_DECLARED_CONSTEXPR_P (decl) = true;
+ if (!processing_template_decl)
+ TREE_TYPE (decl) = complete_type (TREE_TYPE (decl));
+ }
/* Record constancy and volatility on the DECL itself . There's
no need to do this when processing a template; we'll do this
Index: testsuite/g++.dg/cpp0x/constexpr-template11.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-template11.C (revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-template11.C (working copy)
@@ -0,0 +1,16 @@
+// PR c++/65579
+// { dg-do link { target c++11 } }
+
+template <typename>
+struct S {
+ int i;
+};
+
+struct T {
+ static constexpr S<int> s = { 1 };
+};
+
+int main()
+{
+ return T::s.i;
+}