[cfe-commits] r156934 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td include/clang/Parse/Parser.h lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp lib/Parse/ParseObjc.cpp lib/Parse/Parser.cpp test/Misc/warning-flags.c test/Parser/cxx-class.cpp test/Parser/cxx-extra-semi.cpp
Richard Trieu
rtrieu at google.com
Wed May 16 12:05:00 PDT 2012
Author: rtrieu
Date: Wed May 16 14:04:59 2012
New Revision: 156934
URL: http://llvm.org/viewvc/llvm-project?rev=156934&view=rev
Log:
Move the warnings for extra semi-colons under -Wextra-semi. Also, added
a warning for an extra semi-colon after function definitions. Added logic
so that a block of semi-colons on a line will only get one warning instead
of a warning for each semi-colon.
Added:
cfe/trunk/test/Parser/cxx-extra-semi.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/test/Misc/warning-flags.c
cfe/trunk/test/Parser/cxx-class.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=156934&r1=156933&r2=156934&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Wed May 16 14:04:59 2012
@@ -21,15 +21,16 @@
let CategoryName = "Parse Issue" in {
def ext_empty_source_file : Extension<"ISO C forbids an empty source file">;
-def ext_top_level_semi : Extension<
- "extra ';' outside of a function">;
def warn_cxx98_compat_top_level_semi : Warning<
"extra ';' outside of a function is incompatible with C++98">,
InGroup<CXX98CompatPedantic>, DefaultIgnore;
-def ext_extra_struct_semi : Extension<
- "extra ';' inside a %0">;
-def ext_extra_ivar_semi : Extension<
- "extra ';' inside instance variable list">;
+def ext_extra_semi : Extension<
+ "extra ';' %select{"
+ "outside of a function|"
+ "inside a %1|"
+ "inside instance variable list|"
+ "after function definition}0">,
+ InGroup<DiagGroup<"extra-semi">>;
def ext_duplicate_declspec : Extension<"duplicate '%0' declaration specifier">;
def ext_plain_complex : ExtWarn<
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=156934&r1=156933&r2=156934&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Wed May 16 14:04:59 2012
@@ -654,6 +654,17 @@
/// to the semicolon, consumes that extra token.
bool ExpectAndConsumeSemi(unsigned DiagID);
+ /// \brief The kind of extra semi diagnostic to emit.
+ enum ExtraSemiKind {
+ OutsideFunction = 0,
+ InsideStruct = 1,
+ InstanceVariableList = 2,
+ AfterDefinition = 3
+ };
+
+ /// \brief Consume any extra semi-colons until the end of the line.
+ void ConsumeExtraSemi(ExtraSemiKind Kind, const char* DiagMsg = "");
+
//===--------------------------------------------------------------------===//
// Scope manipulation
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=156934&r1=156933&r2=156934&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed May 16 14:04:59 2012
@@ -2701,10 +2701,8 @@
// Check for extraneous top-level semicolon.
if (Tok.is(tok::semi)) {
- Diag(Tok, diag::ext_extra_struct_semi)
- << DeclSpec::getSpecifierName((DeclSpec::TST)TagType)
- << FixItHint::CreateRemoval(Tok.getLocation());
- ConsumeToken();
+ ConsumeExtraSemi(InsideStruct,
+ DeclSpec::getSpecifierName((DeclSpec::TST)TagType));
continue;
}
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=156934&r1=156933&r2=156934&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Wed May 16 14:04:59 2012
@@ -1929,9 +1929,8 @@
LateParsedAttrs.clear();
// Consume the ';' - it's optional unless we have a delete or default
- if (Tok.is(tok::semi)) {
- ConsumeToken();
- }
+ if (Tok.is(tok::semi))
+ ConsumeExtraSemi(AfterDefinition);
return;
}
@@ -2280,10 +2279,8 @@
// Check for extraneous top-level semicolon.
if (Tok.is(tok::semi)) {
- Diag(Tok, diag::ext_extra_struct_semi)
- << DeclSpec::getSpecifierName((DeclSpec::TST)TagType)
- << FixItHint::CreateRemoval(Tok.getLocation());
- ConsumeToken();
+ ConsumeExtraSemi(InsideStruct,
+ DeclSpec::getSpecifierName((DeclSpec::TST)TagType));
continue;
}
@@ -3007,10 +3004,8 @@
// Check for extraneous top-level semicolon.
if (Tok.is(tok::semi)) {
- Diag(Tok, diag::ext_extra_struct_semi)
- << DeclSpec::getSpecifierName((DeclSpec::TST)TagType)
- << FixItHint::CreateRemoval(Tok.getLocation());
- ConsumeToken();
+ ConsumeExtraSemi(InsideStruct,
+ DeclSpec::getSpecifierName((DeclSpec::TST)TagType));
continue;
}
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=156934&r1=156933&r2=156934&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Wed May 16 14:04:59 2012
@@ -1259,9 +1259,7 @@
// Check for extraneous top-level semicolon.
if (Tok.is(tok::semi)) {
- Diag(Tok, diag::ext_extra_ivar_semi)
- << FixItHint::CreateRemoval(Tok.getLocation());
- ConsumeToken();
+ ConsumeExtraSemi(InstanceVariableList);
continue;
}
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=156934&r1=156933&r2=156934&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Wed May 16 14:04:59 2012
@@ -202,6 +202,33 @@
return ExpectAndConsume(tok::semi, DiagID);
}
+void Parser::ConsumeExtraSemi(ExtraSemiKind Kind, const char* DiagMsg) {
+ if (!Tok.is(tok::semi)) return;
+
+ // AfterDefinition should only warn when placed on the same line as the
+ // definition. Otherwise, defer to another semi warning.
+ if (Kind == AfterDefinition && Tok.isAtStartOfLine()) return;
+
+ SourceLocation StartLoc = Tok.getLocation();
+ SourceLocation EndLoc = Tok.getLocation();
+ ConsumeToken();
+
+ while ((Tok.is(tok::semi) && !Tok.isAtStartOfLine())) {
+ EndLoc = Tok.getLocation();
+ ConsumeToken();
+ }
+
+ if (Kind == OutsideFunction && getLangOpts().CPlusPlus0x) {
+ Diag(StartLoc, diag::warn_cxx98_compat_top_level_semi)
+ << FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc));
+ return;
+ }
+
+ Diag(StartLoc, diag::ext_extra_semi)
+ << Kind << DiagMsg << FixItHint::CreateRemoval(SourceRange(StartLoc,
+ EndLoc));
+}
+
//===----------------------------------------------------------------------===//
// Error recovery.
//===----------------------------------------------------------------------===//
@@ -582,11 +609,7 @@
HandlePragmaPack();
return DeclGroupPtrTy();
case tok::semi:
- Diag(Tok, getLangOpts().CPlusPlus0x ?
- diag::warn_cxx98_compat_top_level_semi : diag::ext_top_level_semi)
- << FixItHint::CreateRemoval(Tok.getLocation());
-
- ConsumeToken();
+ ConsumeExtraSemi(OutsideFunction);
// TODO: Invoke action for top-level semicolon.
return DeclGroupPtrTy();
case tok::r_brace:
Modified: cfe/trunk/test/Misc/warning-flags.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/warning-flags.c?rev=156934&r1=156933&r2=156934&view=diff
==============================================================================
--- cfe/trunk/test/Misc/warning-flags.c (original)
+++ cfe/trunk/test/Misc/warning-flags.c Wed May 16 14:04:59 2012
@@ -17,7 +17,7 @@
The list of warnings below should NEVER grow. It should gradually shrink to 0.
-CHECK: Warnings without flags (245):
+CHECK: Warnings without flags (242):
CHECK-NEXT: ext_anonymous_struct_union_qualified
CHECK-NEXT: ext_binary_literal
CHECK-NEXT: ext_cast_fn_obj
@@ -33,8 +33,6 @@
CHECK-NEXT: ext_expected_semi_decl_list
CHECK-NEXT: ext_explicit_instantiation_without_qualified_id
CHECK-NEXT: ext_explicit_specialization_storage_class
-CHECK-NEXT: ext_extra_ivar_semi
-CHECK-NEXT: ext_extra_struct_semi
CHECK-NEXT: ext_forward_ref_enum
CHECK-NEXT: ext_freestanding_complex
CHECK-NEXT: ext_hexconstant_invalid
@@ -65,7 +63,6 @@
CHECK-NEXT: ext_subscript_non_lvalue
CHECK-NEXT: ext_template_arg_extra_parens
CHECK-NEXT: ext_thread_before
-CHECK-NEXT: ext_top_level_semi
CHECK-NEXT: ext_typecheck_addrof_void
CHECK-NEXT: ext_typecheck_cast_nonscalar
CHECK-NEXT: ext_typecheck_cast_to_union
Modified: cfe/trunk/test/Parser/cxx-class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-class.cpp?rev=156934&r1=156933&r2=156934&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx-class.cpp (original)
+++ cfe/trunk/test/Parser/cxx-class.cpp Wed May 16 14:04:59 2012
@@ -14,9 +14,9 @@
public:
void m() {
int l = 2;
- };
+ }; // expected-warning{{extra ';' after function definition}}
- template<typename T> void mt(T) { };
+ template<typename T> void mt(T) { }
; // expected-warning{{extra ';' inside a class}}
virtual int vf() const volatile = 0;
Added: cfe/trunk/test/Parser/cxx-extra-semi.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-extra-semi.cpp?rev=156934&view=auto
==============================================================================
--- cfe/trunk/test/Parser/cxx-extra-semi.cpp (added)
+++ cfe/trunk/test/Parser/cxx-extra-semi.cpp Wed May 16 14:04:59 2012
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -Wextra-semi -verify %s
+// 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();
+ void A2() { }; // expected-warning{{extra ';' after function definition}}
+ ; // expected-warning{{extra ';' inside a class}}
+ void A3() { }; ;; // expected-warning{{extra ';' after function definition}}
+ ;;;;;;; // 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}}
+};
+
+; // expected-warning{{extra ';' outside of a function}}
+; ;;// expected-warning{{extra ';' outside of a function}}
+
More information about the cfe-commits
mailing list