[PATCH] D85590: [clang][HeaderInsert] Do not treat defines with values as header guards
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 11 07:09:46 PDT 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGea8e71c3da56: [clang][HeaderInsert] Do not treat defines with values as header guards (authored by kadircet).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85590/new/
https://reviews.llvm.org/D85590
Files:
clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
clang/unittests/Tooling/HeaderIncludesTest.cpp
Index: clang/unittests/Tooling/HeaderIncludesTest.cpp
===================================================================
--- clang/unittests/Tooling/HeaderIncludesTest.cpp
+++ clang/unittests/Tooling/HeaderIncludesTest.cpp
@@ -347,6 +347,18 @@
EXPECT_EQ(Expected, insert(Code, "<vector>"));
}
+TEST_F(HeaderIncludesTest, FakeHeaderGuardIfnDef) {
+ std::string Code = "#ifndef A_H\n"
+ "#define A_H 1\n"
+ "#endif";
+ std::string Expected = "#include \"b.h\"\n"
+ "#ifndef A_H\n"
+ "#define A_H 1\n"
+ "#endif";
+
+ EXPECT_EQ(Expected, insert(Code, "\"b.h\""));
+}
+
TEST_F(HeaderIncludesTest, HeaderGuardWithComment) {
std::string Code = "// comment \n"
"#ifndef X // comment\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===================================================================
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -100,7 +100,8 @@
[](const SourceManager &SM, Lexer &Lex, Token Tok) -> unsigned {
if (checkAndConsumeDirectiveWithName(Lex, "ifndef", Tok)) {
skipComments(Lex, Tok);
- if (checkAndConsumeDirectiveWithName(Lex, "define", Tok))
+ if (checkAndConsumeDirectiveWithName(Lex, "define", Tok) &&
+ Tok.isAtStartOfLine())
return SM.getFileOffset(Tok.getLocation());
}
return 0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85590.284704.patch
Type: text/x-patch
Size: 1551 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200811/bf1ba0c1/attachment.bin>
More information about the cfe-commits
mailing list