Skip to content

Commit d71ee7d

Browse files
authored
[clang-format] Set C11 instead of C17 for LK_C (llvm#134472)
Fix llvm#134453
1 parent b1cd3cb commit d71ee7d

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

clang/lib/Format/Format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4010,7 +4010,7 @@ LangOptions getFormattingLangOpts(const FormatStyle &Style) {
40104010

40114011
switch (Style.Language) {
40124012
case FormatStyle::LK_C:
4013-
LangOpts.C17 = 1;
4013+
LangOpts.C11 = 1;
40144014
break;
40154015
case FormatStyle::LK_Cpp:
40164016
case FormatStyle::LK_ObjC:

clang/lib/Format/FormatToken.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static SmallVector<StringRef> CppNonKeywordTypes = {
4444
bool FormatToken::isTypeName(const LangOptions &LangOpts) const {
4545
if (is(TT_TypeName) || Tok.isSimpleTypeSpecifier(LangOpts))
4646
return true;
47-
return (LangOpts.CXXOperatorNames || LangOpts.C17) && is(tok::identifier) &&
47+
return (LangOpts.CXXOperatorNames || LangOpts.C11) && is(tok::identifier) &&
4848
std::binary_search(CppNonKeywordTypes.begin(),
4949
CppNonKeywordTypes.end(), TokenText);
5050
}

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ class AnnotatingParser {
129129
: Style(Style), Line(Line), CurrentToken(Line.First), AutoFound(false),
130130
IsCpp(Style.isCpp()), LangOpts(getFormattingLangOpts(Style)),
131131
Keywords(Keywords), Scopes(Scopes), TemplateDeclarationDepth(0) {
132-
assert(IsCpp == (LangOpts.CXXOperatorNames || LangOpts.C17));
133132
Contexts.push_back(Context(tok::unknown, 1, /*IsExpression=*/false));
134133
resetTokenMetadata();
135134
}
@@ -3847,7 +3846,7 @@ static bool isFunctionDeclarationName(const LangOptions &LangOpts,
38473846
};
38483847

38493848
const auto *Next = Current.Next;
3850-
const bool IsCpp = LangOpts.CXXOperatorNames || LangOpts.C17;
3849+
const bool IsCpp = LangOpts.CXXOperatorNames || LangOpts.C11;
38513850

38523851
// Find parentheses of parameter list.
38533852
if (Current.is(tok::kw_operator)) {

clang/lib/Format/TokenAnnotator.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,7 @@ class TokenAnnotator {
224224
public:
225225
TokenAnnotator(const FormatStyle &Style, const AdditionalKeywords &Keywords)
226226
: Style(Style), IsCpp(Style.isCpp()),
227-
LangOpts(getFormattingLangOpts(Style)), Keywords(Keywords) {
228-
assert(IsCpp == (LangOpts.CXXOperatorNames || LangOpts.C17));
229-
}
227+
LangOpts(getFormattingLangOpts(Style)), Keywords(Keywords) {}
230228

231229
/// Adapts the indent levels of comment lines to the indent of the
232230
/// subsequent line.

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ UnwrappedLineParser::UnwrappedLineParser(
167167
? IG_Rejected
168168
: IG_Inited),
169169
IncludeGuardToken(nullptr), FirstStartColumn(FirstStartColumn),
170-
Macros(Style.Macros, SourceMgr, Style, Allocator, IdentTable) {
171-
assert(IsCpp == (LangOpts.CXXOperatorNames || LangOpts.C17));
172-
}
170+
Macros(Style.Macros, SourceMgr, Style, Allocator, IdentTable) {}
173171

174172
void UnwrappedLineParser::reset() {
175173
PPBranchLevel = -1;

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3935,6 +3935,12 @@ TEST_F(TokenAnnotatorTest, UserDefinedConversionFunction) {
39353935
EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_FunctionDeclarationLParen);
39363936
}
39373937

3938+
TEST_F(TokenAnnotatorTest, UTF8StringLiteral) {
3939+
auto Tokens = annotate("return u8\"foo\";", getLLVMStyle(FormatStyle::LK_C));
3940+
ASSERT_EQ(Tokens.size(), 4u) << Tokens;
3941+
EXPECT_TOKEN(Tokens[1], tok::utf8_string_literal, TT_Unknown);
3942+
}
3943+
39383944
} // namespace
39393945
} // namespace format
39403946
} // namespace clang

0 commit comments

Comments
 (0)