Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Missing -Wc++98-compat-extra-semi warning in a class definition #45577

Open Quuxplusone opened 4 years ago

Quuxplusone commented 4 years ago
Bugzilla Link PR46607
Status NEW
Importance P normal
Reported by Haoxin Tu (haoxintu@gmail.com)
Reported on 2020-07-06 09:47:11 -0700
Last modified on 2020-07-06 11:26:40 -0700
Version trunk
Hardware PC Linux
CC llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Hi, all.

This code, test.cc, Clang gives the right -Wc++98-compat-extra-semi warning in
a normal function defintion but misses the warning in function defined inside a
class definition.

$cat test.cc
void foo () { }; //warning
template  <typename> void foo() {}; //warning
class A {
    void foo () { }; //no warning
    template  <typename> void foo() {}; //no warning
};

$clang++ -c -Wc++98-compat-extra-semi test.cc
test.cc:1:16: warning: extra ';' outside of a function is incompatible with
C++98 [-Wc++98-compat-extra-semi]
void foo () { }; //warning
               ^
test.cc:2:35: warning: extra ';' outside of a function is incompatible with
C++98 [-Wc++98-compat-extra-semi]
template  <typename> void foo() {}; //warning
                                  ^
2 warnings generated.

I guess Clang should treats the same with above four lines. Is clang dealing
with this code for intentionally?

Every version from clang 7.0 to trunk behaves the same.

Thanks,
Haoxin
Quuxplusone commented 4 years ago
The C++98 specification strangely permitted an optional semicolon after a
member function definition:

member-declaration:
    function-definition ;[opt]

As a consequence, clang allows a single semicolon in this position but
diagnoses if there are two or more semicolons.

I think the case with a member function *template* is a minor bug, though: that
uses a different grammar production that does not permit a trailing semicolon,
so pedantically we should diagnose that, even though it will make the behaviour
in your testcase look even more arbitrary.