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

            Bug ID: 121333
           Summary: g++ and clang++ diverge on parsing new
                    (std::nothrow_t())
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jirehguo at tju dot edu.cn
  Target Milestone: ---

g++ accepts following code. However, clang++ and msvc rejects it.
Is one compiler incorrect?
Repro: https://godbolt.org/z/fzT7vaaov

Clang++ output:
---------------
<source>:4:20: error: cannot allocate function type 'std::nothrow_t ()' with
new
    4 |     char *p = new (std::nothrow_t()) char[1];
      |                    ^~~~~~~~~~~~~~~~
1 error generated.


MSVC output: 
---------------
example.cpp
<source>(4): error C2066: cast to function type is illegal
<source>(4): error C2144: syntax error: 'char' should be preceded by ';'
<source>(4): error C2760: syntax error: 'constant' was unexpected here;
expected 'id-expression'
<source>(4): error C2059: syntax error: ';'


Code:
---------------
#include <new> 

int main() {
    char *p = new (std::nothrow_t()) char[1];
    return 0;
}

Reply via email to