diff options
author | Jason Merrill <jason@redhat.com> | 2018-05-10 22:54:52 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2018-05-10 22:54:52 -0400 |
commit | 683be2f77b3ce4db09e1175c1de4ec7f26f803e6 (patch) | |
tree | 88252de62c5b24bace7e3d670e293b2580edb27f /gcc | |
parent | 3a2e98ce726393a48c818d097ba021baa7b6633b (diff) | |
download | gcc-683be2f77b3ce4db09e1175c1de4ec7f26f803e6.zip gcc-683be2f77b3ce4db09e1175c1de4ec7f26f803e6.tar.gz gcc-683be2f77b3ce4db09e1175c1de4ec7f26f803e6.tar.bz2 |
decl.c (cp_finish_decl): Don't instantiate auto variable.
* decl.c (cp_finish_decl): Don't instantiate auto variable.
(check_static_variable_definition): Allow auto.
* constexpr.c (ensure_literal_type_for_constexpr_object): Likewise.
From-SVN: r260150
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/constexpr.c | 2 | ||||
-rw-r--r-- | gcc/cp/decl.c | 21 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1z/static2.C | 17 |
4 files changed, 32 insertions, 14 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bee1112..920bed4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,4 +1,8 @@ -2018-05-09 Jason Merrill <jason@redhat.com> +2018-05-10 Jason Merrill <jason@redhat.com> + + * decl.c (cp_finish_decl): Don't instantiate auto variable. + (check_static_variable_definition): Allow auto. + * constexpr.c (ensure_literal_type_for_constexpr_object): Likewise. * cp-tree.h (DECL_CONSTRUCTOR_P): Use DECL_CXX_CONSTRUCTOR_P. (DECL_DESTRUCTOR_P): Use DECL_CXX_DESTRUCTOR_P. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index b4bcc6a..d9a4cab 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -91,6 +91,8 @@ ensure_literal_type_for_constexpr_object (tree decl) if (CLASS_TYPE_P (stype) && !COMPLETE_TYPE_P (complete_type (stype))) /* Don't complain here, we'll complain about incompleteness when we try to initialize the variable. */; + else if (type_uses_auto (type)) + /* We don't know the actual type yet. */; else if (!literal_type_p (type)) { if (DECL_DECLARED_CONSTEXPR_P (decl)) diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index d589647..20ca28f 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6803,24 +6803,18 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, && (DECL_INITIAL (decl) || init)) DECL_INITIALIZED_IN_CLASS_P (decl) = 1; + /* Do auto deduction unless decl is a function or an uninstantiated + template specialization. */ if (TREE_CODE (decl) != FUNCTION_DECL + && !(init == NULL_TREE + && DECL_LANG_SPECIFIC (decl) + && DECL_TEMPLATE_INSTANTIATION (decl) + && !DECL_TEMPLATE_INSTANTIATED (decl)) && (auto_node = type_uses_auto (type))) { tree d_init; if (init == NULL_TREE) - { - if (DECL_LANG_SPECIFIC (decl) - && DECL_TEMPLATE_INSTANTIATION (decl) - && !DECL_TEMPLATE_INSTANTIATED (decl)) - { - /* init is null because we're deferring instantiating the - initializer until we need it. Well, we need it now. */ - instantiate_decl (decl, /*defer_ok*/true, /*expl*/false); - return; - } - - gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (auto_node)); - } + gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (auto_node)); d_init = init; if (d_init) { @@ -9368,6 +9362,7 @@ check_static_variable_definition (tree decl, tree type) in check_initializer. Similarly for inline static data members. */ if (DECL_P (decl) && (DECL_DECLARED_CONSTEXPR_P (decl) + || undeduced_auto_decl (decl) || DECL_VAR_DECLARED_INLINE_P (decl))) return 0; else if (cxx_dialect >= cxx11 && !INTEGRAL_OR_ENUMERATION_TYPE_P (type)) diff --git a/gcc/testsuite/g++.dg/cpp1z/static2.C b/gcc/testsuite/g++.dg/cpp1z/static2.C new file mode 100644 index 0000000..b87bfec --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/static2.C @@ -0,0 +1,17 @@ +// { dg-additional-options -std=c++17 } + +template <class T> +struct A +{ + static constexpr auto x = T::x; +}; + +struct B; +A<B> a; + +struct B +{ + static constexpr auto x = 42; +}; + +auto x = a.x; |