Clang accepts empty declaration in a template declaration
| Bugzilla Link | 46231 |
| Resolution | FIXED |
| Resolved on | Jul 29, 2020 12:36 |
| Version | trunk |
| OS | Linux |
| CC | @DougGregor,@zygoloid |
| Fixed by commit(s) | llvmorg-12-init-1498-g1cbdf932b41 |
Extended Description
Hi, there,
clang accepts this code --- test.cc:
template
which contains a empty declaration in a template declaration.
In clang-trunk, clang just give a warning and then compile it successfully.
$clang++-trunk test.cc
test.cc:1:16: warning: declaration does not declare anything [-Wmissing-declarations]
template
But in gcc, icc, or msvc, they all fail to compile it.
For example, in gcc
$g++ test.cc
test.cc:1:16: error: expected unqualified-id before ‘;’ token
1 | template
^
I also tested in other released clang versions, they all accepts test.cc.
Clang was previously producing an extension warning, which was promoted to an error with -pedantic-errors, so this was an extension (albeit an accidental one, as far as I can tell) rather than a bug.
However, no other C++ compiler accepts such constructs, not even in permissive mode, so we're not doing anyone a favor by allowing this. I've converted it to being a hard error.
Hi.
Add a more test case cased by this issue.
$cat test.cc extern "C" { template < typename >; }
Clang just accepts this without any diagnostic in "template with C linkage".
While in GCC $g++ test.cc test.cc:2:5: error: template with C linkage 2 | template < typename >; | ^~~~~~~~ test.cc:1:1: note: 'extern "C"' linkage started here 1 | extern "C" { | ^~~~~~~~~~~ test.cc:2:26: error: expected unqualified-id before ';' token 2 | template < typename >; |
Thanks.