Skip to content

Commit 8697bbe

Browse files
authored
[clang] Use CPlusPlus language option instead of Bool (#80975)
As it was pointed out in #80724, we should not be checking `getLangOpts().Bool` when determining something related to logical operators, since it only indicates that bool keyword is present, not which semantic logical operators have. As a side effect a missing `-Wpointer-bool-conversion` in OpenCL C was restored since like C23, OpenCL C has bool keyword but logical operators still return int.
1 parent 72f04fa commit 8697bbe

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16129,10 +16129,10 @@ static void CheckConditionalOperator(Sema &S, AbstractConditionalOperator *E,
1612916129
/// Check conversion of given expression to boolean.
1613016130
/// Input argument E is a logical expression.
1613116131
static void CheckBoolLikeConversion(Sema &S, Expr *E, SourceLocation CC) {
16132-
// While C23 does have bool as a keyword, we still need to run the bool-like
16133-
// conversion checks as bools are still not used as the return type from
16134-
// "boolean" operators or as the input type for conditional operators.
16135-
if (S.getLangOpts().Bool && !S.getLangOpts().C23)
16132+
// Run the bool-like conversion checks only for C since there bools are
16133+
// still not used as the return type from "boolean" operators or as the input
16134+
// type for conditional operators.
16135+
if (S.getLangOpts().CPlusPlus)
1613616136
return;
1613716137
if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
1613816138
return;

clang/test/SemaOpenCL/operators.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,6 @@ kernel void pointer_ops(){
118118
bool b = !p;
119119
b = p==0;
120120
int i;
121-
b = !&i;
121+
b = !&i; // expected-warning {{address of 'i' will always evaluate to 'true'}}
122122
b = &i==(int *)1;
123123
}

0 commit comments

Comments
 (0)