2012-07-23 13:45:25 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -pedantic -verify -DPEDANTIC %s
|
2012-05-17 03:04:59 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -Wextra-semi -verify %s
|
2012-07-23 13:45:25 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -Wextra-semi -verify -std=c++11 %s
|
2012-05-17 03:04:59 +08:00
|
|
|
// RUN: cp %s %t
|
|
|
|
// RUN: %clang_cc1 -x c++ -Wextra-semi -fixit %t
|
|
|
|
// RUN: %clang_cc1 -x c++ -Wextra-semi -Werror %t
|
|
|
|
|
|
|
|
class A {
|
|
|
|
void A1();
|
2012-07-23 13:45:25 +08:00
|
|
|
void A2() { };
|
|
|
|
#ifndef PEDANTIC
|
|
|
|
// This warning is only produced if we specify -Wextra-semi, and not if only
|
|
|
|
// -pedantic is specified, since one semicolon is technically permitted.
|
|
|
|
// expected-warning@-4{{extra ';' after member function definition}}
|
|
|
|
#endif
|
|
|
|
void A2b() { };; // expected-warning{{extra ';' after member function definition}}
|
2012-05-17 03:04:59 +08:00
|
|
|
; // expected-warning{{extra ';' inside a class}}
|
2012-07-23 13:45:25 +08:00
|
|
|
void A2c() { }
|
|
|
|
;
|
|
|
|
#ifndef PEDANTIC
|
|
|
|
// expected-warning@-2{{extra ';' after member function definition}}
|
|
|
|
#endif
|
|
|
|
void A3() { }; ;; // expected-warning{{extra ';' after member function definition}}
|
2012-05-17 03:04:59 +08:00
|
|
|
;;;;;;; // expected-warning{{extra ';' inside a class}}
|
|
|
|
; // expected-warning{{extra ';' inside a class}}
|
|
|
|
; ;; ; ;;; // expected-warning{{extra ';' inside a class}}
|
|
|
|
; ; ; ; ;; // expected-warning{{extra ';' inside a class}}
|
|
|
|
void A4();
|
|
|
|
};
|
|
|
|
|
|
|
|
union B {
|
|
|
|
int a1;
|
|
|
|
int a2;; // expected-warning{{extra ';' inside a union}}
|
|
|
|
};
|
|
|
|
|
2012-07-23 13:45:25 +08:00
|
|
|
;
|
|
|
|
; ;;
|
|
|
|
#if __cplusplus < 201103L
|
|
|
|
// expected-warning@-3{{extra ';' outside of a function is a C++11 extension}}
|
|
|
|
// expected-warning@-3{{extra ';' outside of a function is a C++11 extension}}
|
[Parser] (C++) Make -Wextra-semi slightly more useful
Summary:
Let's suppose the `-Weverything` is passed.
Given code like
```
void F() {}
;
```
If the code is compiled with `-std=c++03`, it would diagnose that extra sema:
```
<source>:2:1: warning: extra ';' outside of a function is a C++11 extension [-Wc++11-extra-semi]
;
^~
```
If the code is compiled with `-std=c++11`, it also would diagnose that extra sema:
```
<source>:2:1: warning: extra ';' outside of a function is incompatible with C++98 [-Wc++98-compat-pedantic]
;
^~
```
But, let's suppose the C++11 or higher is used, and the used does not care
about `-Wc++98-compat-pedantic`, so he disables that diagnostic.
And that silences the complaint about extra `;` too.
And there is no way to re-enable that particular diagnostic, passing `-Wextra-semi` does nothing...
Now, there is also a related `no newline at end of file` diagnostic, which is also emitted by `-Wc++98-compat-pedantic`
```
<source>:2:2: warning: C++98 requires newline at end of file [-Wc++98-compat-pedantic]
;
^
```
But unlike the previous case, if `-Wno-c++98-compat-pedantic` is passed, that diagnostic stays displayed:
```
<source>:2:2: warning: no newline at end of file [-Wnewline-eof]
;
^
```
This diff refactors the code so `-Wc++98-compat-extra-semi` can be re-enabled, after the `-Wc++98-compat-pedantic` was disabled.
This seems ugly, but there does not seem to be any saner way.
Testing: `$ ninja check-clang`
Reviewers: rsmith, rtrieu, aaron.ballman
Reviewed By: aaron.ballman
Subscribers: jordan_rose, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D43162
llvm-svn: 327558
2018-03-15 03:31:34 +08:00
|
|
|
#elif !defined(PEDANTIC)
|
|
|
|
// expected-warning@-6{{extra ';' outside of a function is incompatible with C++98}}
|
|
|
|
// expected-warning@-6{{extra ';' outside of a function is incompatible with C++98}}
|
2012-07-23 13:45:25 +08:00
|
|
|
#endif
|