aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/runtime
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2021-12-16 14:57:07 -0500
committerMarek Polacek <polacek@redhat.com>2021-12-17 13:08:17 -0500
commitfae016862631da70e6482fe3173a111248f8b9bc (patch)
tree7df53a4ee969e86cb50294e6f92a04188336e940 /libgfortran/runtime
parent87ae8d7613a8b15d0d729b38ffd49153f1314799 (diff)
downloadgcc-fae016862631da70e6482fe3173a111248f8b9bc.zip
gcc-fae016862631da70e6482fe3173a111248f8b9bc.tar.gz
gcc-fae016862631da70e6482fe3173a111248f8b9bc.tar.bz2
c++: Improve diagnostic for class tmpl/class redecl [PR103749]
For code like template<typename> struct bar; struct bar { int baz; }; bar var; we emit a fairly misleading and unwieldy diagnostic: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $ g++ -c u.cc u.cc:6:8: error: template argument required for 'struct bar' 6 | struct bar { | ^~~ u.cc:10:5: error: class template argument deduction failed: 10 | bar var; | ^~~ u.cc:10:5: error: no matching function for call to 'bar()' u.cc:3:17: note: candidate: 'template<class> bar()-> bar< <template-parameter-1-1> >' 3 | friend struct bar; | ^~~ u.cc:3:17: note: template argument deduction/substitution failed: u.cc:10:5: note: couldn't deduce template parameter '<template-parameter-1-1>' 10 | bar var; | ^~~ u.cc:3:17: note: candidate: 'template<class> bar(bar< <template-parameter-1-1> >)-> bar< <template-parameter-1-1> >' 3 | friend struct bar; | ^~~ u.cc:3:17: note: template argument deduction/substitution failed: u.cc:10:5: note: candidate expects 1 argument, 0 provided 10 | bar var; | ^~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ but with this patch we get: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ z.C:4:10: error: class template 'bar' redeclared as non-template 4 | struct bar { | ^~~ z.C:2:10: note: previous declaration here 2 | struct bar; | ^~~ z.C:8:7: error: 'bar<...auto...> var' has incomplete type 8 | bar var; | ^~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ which is clearer about what the problem is. I thought it'd be nice to avoid printing the messages about failed CTAD, too. To that end, I'm using CLASSTYPE_ERRONEOUS to suppress CTAD. Not sure if that's entirely kosher. The other direction (first a non-template class declaration followed by a class template definition) we handle quite well: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ z.C:11:8: error: 'bar' is not a template 11 | struct bar {}; | ^~~ z.C:8:8: note: previous declaration here 8 | struct bar; | ^~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PR c++/103749 gcc/cp/ChangeLog: * decl.c (lookup_and_check_tag): Give an error when a class was declared as template but no template header has been provided. * pt.c (do_class_deduction): Don't deduce CLASSTYPE_ERRONEOUS types. gcc/testsuite/ChangeLog: * g++.dg/template/redecl4.C: Adjust dg-error. * g++.dg/diagnostic/redeclaration-2.C: New test.
Diffstat (limited to 'libgfortran/runtime')
0 files changed, 0 insertions, 0 deletions