You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[clang-tidy] bugprone-macro-repeated-side-effects false positive with assert() in glibc 2.44 #233597
In glibc 2.44, the definition of the assert() macro changed to accommodate the C++26 feature that allows non-parenthesised commas within assertions. The relevant part is this:
Note that __VA_ARGS__ is only evaluated once, even though it appears twice. Unfortunately, this makes clang-tidy produce the bugprone-macro-repeated-side-effects warning in code like this, even if bugprone-assert-side-effect is not enabled:
#include<cassert>intmain() {
int x = 0;
assert(++x == 1);
assert(++x == 1);
}
The result:
warning: side effects in the 1st macro argument '__VA_ARGS__' are repeated in macro expansion [bugprone-macro-repeated-side-effects]
4 | assert( ++x == 1 );
| ^
/usr/include/assert.h:137:13: note: macro 'assert' defined here
137 | # define assert(...) \
| ^
warning: side effects in the 1st macro argument '__VA_ARGS__' are repeated in macro expansion [bugprone-macro-repeated-side-effects]
5 | assert( ++x == 2 );
| ^
/usr/include/assert.h:137:13: note: macro 'assert' defined here
137 | # define assert(...) \
| ^
Perhaps the bugprone-macro-repeated-side-effects could specifically ignore the assert() macro; or, even better, it could be configurable with an option to ignore specific macros.
Details
In glibc 2.44, the definition of the `assert()` macro changed to accommodate the C++26 feature that allows non-parenthesised commas within assertions. The relevant part is this:
Note that __VA_ARGS__ is only evaluated once, even though it appears twice. Unfortunately, this makes clang-tidy produce the bugprone-macro-repeated-side-effects warning in code like this, even if bugprone-assert-side-effect is not enabled:
#include <cassert>
intmain() {
int x = 0;
assert(++x == 1);
assert(++x == 1);
}
The result:
warning: side effects in the 1st macro argument '__VA_ARGS__' are repeated in macro expansion [bugprone-macro-repeated-side-effects]
4 | assert( ++x == 1 );
| ^
/usr/include/assert.h:137:13: note: macro 'assert' defined here
137 | # define assert(...) \
| ^
warning: side effects in the 1st macro argument '__VA_ARGS__' are repeated in macro expansion [bugprone-macro-repeated-side-effects]
5 | assert( ++x == 2 );
| ^
/usr/include/assert.h:137:13: note: macro 'assert' defined here
137 | # define assert(...) \
| ^
Perhaps the bugprone-macro-repeated-side-effects could specifically ignore the assert macro; or, even better, it could be configurable with an option to ignore specific macros.
Activity
llvmorg-github-actions commentedon Oct 19, 2026
@llvm/issue-subscribers-clang-tidy
Author: Nikola Beneš (nikola-benes)
Details
In glibc 2.44, the definition of the `assert()` macro changed to accommodate the C++26 feature that allows non-parenthesised commas within assertions. The relevant part is this:(source: https://sourceware.org/git/?p=glibc.git;a=blob;f=assert/assert.h;hb=ea37298b65bd67f94c3c2640e91ec5865a5019ad#l137)
Note that
__VA_ARGS__is only evaluated once, even though it appears twice. Unfortunately, this makes clang-tidy produce the bugprone-macro-repeated-side-effects warning in code like this, even if bugprone-assert-side-effect is not enabled:The result:
Perhaps the bugprone-macro-repeated-side-effects could specifically ignore the assert macro; or, even better, it could be configurable with an option to ignore specific macros.
[libc++][test] Avoid assert() in gnu/hash/specializations.verify.cpp (#…
Automerge: [libc++][test] Avoid assert() in gnu/hash/specializations.…
Automerge: [libc++][test] Avoid assert() in gnu/hash/specializations.…
[libc++][test] Avoid assert() in gnu/hash/specializations.verify.cpp (l…
[libc++][test] Avoid assert() in gnu/hash/specializations.verify.cpp …