diff options
author | Jason Merrill <jason@redhat.com> | 2022-03-23 18:01:20 -0700 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2022-04-29 14:22:27 -0400 |
commit | 8d0fcf135857869f7cff36d29bc3527c482372a9 (patch) | |
tree | 231843bc29a0076c60ca961aec1124b888156ba9 /gcc/cp/decl.cc | |
parent | 4a8b45e8bc8246bd141dad65f571a3e0cc499c6b (diff) | |
download | gcc-8d0fcf135857869f7cff36d29bc3527c482372a9.zip gcc-8d0fcf135857869f7cff36d29bc3527c482372a9.tar.gz gcc-8d0fcf135857869f7cff36d29bc3527c482372a9.tar.bz2 |
c++: check completeness after auto deduction [PR80351]
Normally we check for incomplete type in start_decl, but that obviously
doesn't work for auto variables. Thanks to Pokechu22 for the analysis and
testcases:
"When cp_finish_decl calls cp_apply_type_quals_to_decl on a const auto or
constexpr auto variable, the type might not be complete the first time
(this happened when auto deduces to an initializer_list).
cp_apply_type_quals_to_decl removes the const qualifier if the type is
not complete, which is appropriate for grokdeclarator, on the assumption
that the type will be complete when called by cp_finish_decl."
PR c++/80351
gcc/cp/ChangeLog:
* decl.cc (cp_finish_decl): Check completeness of deduced type.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/constexpr-77482.C: Adjust message.
* g++.dg/cpp1y/auto-fn27.C: Likewise.
* g++.dg/cpp1y/lambda-generic-variadic22.C: Likewise.
* g++.dg/cpp1z/decomp54.C: Likewise.
* g++.dg/cpp0x/initlist-const1.C: New test.
* g++.dg/warn/Wunused-var-37.C: New test.
* g++.dg/warn/Wunused-var-38.C: New test.
* g++.dg/warn/Wunused-var-39.C: New test.
Diffstat (limited to 'gcc/cp/decl.cc')
-rw-r--r-- | gcc/cp/decl.cc | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 2852093..45206c2 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -8129,6 +8129,17 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, TREE_TYPE (decl) = error_mark_node; return; } + /* As in start_decl_1, complete so TREE_READONLY is set properly. */ + if (!processing_template_decl + && !type_uses_auto (type) + && !COMPLETE_TYPE_P (complete_type (type))) + { + error_at (location_of (decl), + "deduced type %qT for %qD is incomplete", type, decl); + cxx_incomplete_type_inform (type); + TREE_TYPE (decl) = error_mark_node; + return; + } cp_apply_type_quals_to_decl (cp_type_quals (type), decl); } |