Message ID | 20160803194915.GE7007@redhat.com |
---|---|
State | New |
Headers | show |
OK. On Wed, Aug 3, 2016 at 3:49 PM, Marek Polacek <polacek@redhat.com> wrote: > In C++11, constexpr constructor must have an empty body except for > several cases, one of them being: > - typedef declarations and alias-declarations that do not define > classes or enumerations > But we were rejecting constexpr constructors consisting of a typedef > declaration only. > > Bootstrapped/regtested on x86_64-linux, ok for trunk? > > 2016-08-03 Marek Polacek <polacek@redhat.com> > > PR c++/70229 > * constexpr.c (check_constexpr_ctor_body_1): Allow typedef > declarations. > > * g++.dg/cpp0x/constexpr-ctor19.C: New test. > > diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c > index edade48..41665c5 100644 > --- gcc/cp/constexpr.c > +++ gcc/cp/constexpr.c > @@ -425,7 +425,8 @@ check_constexpr_ctor_body_1 (tree last, tree list) > switch (TREE_CODE (list)) > { > case DECL_EXPR: > - if (TREE_CODE (DECL_EXPR_DECL (list)) == USING_DECL) > + if (TREE_CODE (DECL_EXPR_DECL (list)) == USING_DECL > + || TREE_CODE (DECL_EXPR_DECL (list)) == TYPE_DECL) > return true; > return false; > > diff --git gcc/testsuite/g++.dg/cpp0x/constexpr-ctor19.C gcc/testsuite/g++.dg/cpp0x/constexpr-ctor19.C > index e69de29..f5ef053 100644 > --- gcc/testsuite/g++.dg/cpp0x/constexpr-ctor19.C > +++ gcc/testsuite/g++.dg/cpp0x/constexpr-ctor19.C > @@ -0,0 +1,42 @@ > +// PR c++/70229 > +// { dg-do compile { target c++11 } } > + > +template <class> > +class S { > + constexpr S (void) { > + typedef int T; > + } > +}; > + > +template <class> > +class S2 { > + constexpr S2 (void) { > + ; > + } > +}; > + > +template <class> > +class S3 { > + constexpr S3 (void) { > + typedef enum { X } E; > + } // { dg-error "does not have empty body" "" { target c++11_only } } > +}; > + > +template <class> > +class S4 { > + constexpr S4 (void) { > + typedef struct { int j; } U; > + } // { dg-error "does not have empty body" "" { target c++11_only } } > +}; > + > +struct V > +{ > + int i; > +}; > + > +template <class> > +class S5 { > + constexpr S5 (void) { > + typedef V W; > + } > +}; > > Marek
diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c index edade48..41665c5 100644 --- gcc/cp/constexpr.c +++ gcc/cp/constexpr.c @@ -425,7 +425,8 @@ check_constexpr_ctor_body_1 (tree last, tree list) switch (TREE_CODE (list)) { case DECL_EXPR: - if (TREE_CODE (DECL_EXPR_DECL (list)) == USING_DECL) + if (TREE_CODE (DECL_EXPR_DECL (list)) == USING_DECL + || TREE_CODE (DECL_EXPR_DECL (list)) == TYPE_DECL) return true; return false; diff --git gcc/testsuite/g++.dg/cpp0x/constexpr-ctor19.C gcc/testsuite/g++.dg/cpp0x/constexpr-ctor19.C index e69de29..f5ef053 100644 --- gcc/testsuite/g++.dg/cpp0x/constexpr-ctor19.C +++ gcc/testsuite/g++.dg/cpp0x/constexpr-ctor19.C @@ -0,0 +1,42 @@ +// PR c++/70229 +// { dg-do compile { target c++11 } } + +template <class> +class S { + constexpr S (void) { + typedef int T; + } +}; + +template <class> +class S2 { + constexpr S2 (void) { + ; + } +}; + +template <class> +class S3 { + constexpr S3 (void) { + typedef enum { X } E; + } // { dg-error "does not have empty body" "" { target c++11_only } } +}; + +template <class> +class S4 { + constexpr S4 (void) { + typedef struct { int j; } U; + } // { dg-error "does not have empty body" "" { target c++11_only } } +}; + +struct V +{ + int i; +}; + +template <class> +class S5 { + constexpr S5 (void) { + typedef V W; + } +};