When trying to evaluate a comma operator with static_assertwhen argument compilation fails
static_assert
void fvoid() {} int main() { int a = (1, 2); // a=2 int b = (fvoid(), 3); // b=3 int d = ( , 5); // ^ // error: expected primary-expression before ',' token. OK int c = (static_assert(true), 4); // ^~~~~~~~~~~~~ // error: expected primary-expression before 'static_assert'. Why? }
It static_assert()doesn't seem to even allow voidafter compilation. I could not find anything about this in the standard. Is there a way to use it with a comma operator, or use it according to another expression (without a semicolon)?
static_assert()
void
No no. Language grammar requires a semicolon at the end of a static statement declaration.
N4140 §7 [dcl.dcl] / 1static_assert declaration:static_assert (expression constant, literal string );
N4140 §7 [dcl.dcl] / 1
static_assert declaration:
static_assert (expression constant, literal string );
static_assert (
)
( )?
, static_assert., , , - - :
int main() { int c = ([]{ static_assert(true, "!"); }(), 4); }
, - , true.() ( ).- . :
true
template<bool b> void f() { int c = ([](){ static_assert(b, "!"); }(), 4); // ... }
, , ( godbolt, ).
You can simply wrap it in a block:
int c = ({ static_assert(true); }, 4);
Source: https://habr.com/ru/post/1661092/More articles:The sum of each two columns in a Pandas dataframe - pythonUncaught ReferenceError: ytcfg is undefined, although I will not use it since I use yt player - angularjsNavigationView setNavigationItemSelectedListener this API is marked as internal for the support library and should not be accessible from applications - androidhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1661090/regexoptionsmultiline-seems-to-ignore-n&usg=ALkJrhjZTw3wrGyJBbxOxwyU3qKQWN-V2QПроблемы при слиянии двух pandas данных с разными формами? - pythonsave dependecy graph in python - pythonhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1661094/objective-c-indirect-pointer-bound-to-block-fails-to-update-direct-pointer&usg=ALkJrhjgZ3TDB6xx7ihANbSuzU3ZE-cifgCan the Tkinter button have children? - pythonPolyfill for TextDecoder - javascriptDelegation method called twice in Xcode 8.1 / Swift 3.0 with a debugger breakpoint - method-overridingAll Articles