def warn_compound_token_split_by_macro : Warning<
"%sub{subst_compound_token_kind}0,1,2,3 appear in different "
"macro expansion contexts">, InGroup<CompoundTokenSplitByMacro>;
-def warn_compound_token_split_by_file : Warning<
- "%sub{subst_compound_token_kind}0,1,2,3 appear in different source files">,
- InGroup<CompoundTokenSplit>;
def note_compound_token_split_second_token_here : Note<
"%select{|second }0%1 token is here">;
def warn_compound_token_split_by_whitespace : Warning<
return;
SourceLocation SecondTokLoc = Tok.getLocation();
- // We expect both tokens to come from the same FileID.
- FileID FirstID = PP.getSourceManager().getFileID(FirstTokLoc);
- FileID SecondID = PP.getSourceManager().getFileID(SecondTokLoc);
- if (FirstID != SecondID) {
- Diag(FirstTokLoc, (FirstTokLoc.isMacroID() || SecondTokLoc.isMacroID())
- ? diag::warn_compound_token_split_by_macro
- : diag::warn_compound_token_split_by_file)
+ // If either token is in a macro, we expect both tokens to come from the same
+ // macro expansion.
+ if ((FirstTokLoc.isMacroID() || SecondTokLoc.isMacroID()) &&
+ PP.getSourceManager().getFileID(FirstTokLoc) !=
+ PP.getSourceManager().getFileID(SecondTokLoc)) {
+ Diag(FirstTokLoc, diag::warn_compound_token_split_by_macro)
<< (FirstTokKind == Tok.getKind()) << FirstTokKind << Tok.getKind()
<< static_cast<int>(Op) << SourceRange(FirstTokLoc);
Diag(SecondTokLoc, diag::note_compound_token_split_second_token_here)
}
// We expect the tokens to abut.
- if (Tok.hasLeadingSpace()) {
+ if (Tok.hasLeadingSpace() || Tok.isAtStartOfLine()) {
SourceLocation SpaceLoc = PP.getLocForEndOfToken(FirstTokLoc);
if (SpaceLoc.isInvalid())
SpaceLoc = FirstTokLoc;
// RUN: %clang_cc1 %s -verify
// RUN: %clang_cc1 %s -verify=expected,space -Wcompound-token-split
+// Ensure we get the same warnings after -frewrite-includes
+// RUN: %clang_cc1 %s -E -frewrite-includes -o %t
+// RUN: %clang_cc1 -x c++ %t -verify=expected,space -Wcompound-token-split
+
#ifdef LSQUARE
-[ // expected-note {{second '[' token is here}}
+[
#else
#define VAR(type, name, init) type name = (init)
return n;
}
-[ // expected-warning-re {{{{^}}'[' tokens introducing attribute appear in different source files}}
+[ // space-warning-re {{{{^}}'[' tokens introducing attribute are separated by whitespace}}
#define LSQUARE
#include __FILE__
noreturn ]] void g();