https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123203

            Bug ID: 123203
           Summary: typo in static_assert gives confusing and verbose
                    diagnostics
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

I typo'd the closing paren of a static_assert:

constexpr bool test() { return true; }
static_assert( test() };

And got this:

sa.cc:2:22: error: expected ',' before '}' token
    2 | static_assert( test() };
      |                      ^~
      |                      ,
sa.cc:2:23: warning: 'static_assert' with non-string message only available
with '-std=c++2c' or '-std=gnu++2c' [-Wc++26-extensions]
    2 | static_assert( test() };
      |                       ^
sa.cc:2:23: error: expected primary-expression before '}' token
sa.cc:2:22: error: expected ')' before '}' token
    2 | static_assert( test() };
      |              ~       ^~
      |                      )
sa.cc:2:22: error: expected ';' before '}' token
    2 | static_assert( test() };
      |                      ^~
      |                      ;
sa.cc:2:23: error: expected declaration before '}' token
    2 | static_assert( test() };
      |                       ^


It would be nice if it just pointed out the } and showed the fix-it

Saying that a comma *and* a closing paren *and* a declaration is expected seems
a bit noisy. And the -Wc++26-extensions warning is bogus, there's no way that
test()} can be a user-defined string-like type.

Reply via email to