-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Closed
Closed
Copy link
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"code-quality
Description
Warning: Suggest parentheses around '&&' within '||' in SemaTemplateInstantiate.cpp
Summary
While building Clang as part of the LLVM project, a compiler warning appears in
clang/lib/Sema/SemaTemplateInstantiate.cpp
suggesting parentheses around &&
within ||
.
/home/aitr/llvm/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp:2866:49: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
2866 | assert(!Success || !Trap.hasErrorOccurred() &&
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~
2867 | "Substitution failures must be handled "
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2868 | "by CheckConstraintSatisfaction.");
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Steps to Reproduce
-
Clone the LLVM project:
git clone https://github.com/llvm/llvm-project.git cd llvm-project mkdir build && cd build
-
Configure the build using CMake:
cmake -G Ninja ../llvm \ -DLLVM_ENABLE_PROJECTS="clang;lld" \ -DLLVM_USE_LINKER=lld \ -DLLVM_PARALLEL_LINK_JOBS=1 \ -DCMAKE_BUILD_TYPE=Debug \ -DLLVM_ENABLE_ASSERTIONS=ON \ -DLLVM_TARGETS_TO_BUILD="AMDGPU;PowerPC;AArch64;X86" \ -DLLVM_ENABLE_DUMP=ON
-
Build Clang:
ninja clang
-
Observe the warning during compilation of:
clang/lib/Sema/SemaTemplateInstantiate.cpp
Analysis
The expression triggering the warning is:
assert(!Success || !Trap.hasErrorOccurred() &&
"Substitution failures must be handled "
"by CheckConstraintSatisfaction.");
Operator precedence causes &&
to bind tighter than ||
, which may lead to ambiguous intent. Although semantically correct, adding parentheses improves clarity and suppresses warnings.
Proposed Fix
Wrap the &&
clause with parentheses for clarity:
assert(!Success || (!Trap.hasErrorOccurred() &&
"Substitution failures must be handled "
"by CheckConstraintSatisfaction."));
Metadata
Metadata
Assignees
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"code-quality