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

            Bug ID: 119043
           Summary: GCC 14.2 Fails to Parse Empty Attribute [[ ]] in Array
                    new Expression
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: qurong at ios dot ac.cn
  Target Milestone: ---

GCC 14.2 incorrectly rejects array new expressions containing empty attribute
specifiers ([[ ]]), while MSVC and Clang accept them as valid C++ code. This
violates the C++ standard syntax rules.


For the following code test.cpp:

```
int main() {
    auto p = new int[5][[]]; // Empty attribute [[ ]]
    delete[] p;
    return 0;
}
```
Compile with GCC 14.2:

g++ -std=c++17 test.cpp

Expected Result:
Compilation succeeds, as empty attributes [[ ]] are explicitly allowed by the
C++ standard.

Actual Result:
GCC 14.2 reports:
test.cpp: In function ‘int main()’:
test.cpp:2:28: error: expected primary-expression before ‘]’ token
    2 |     auto p = new int[5][[]];
      |                            ^
Environment:
Compiler: GCC 14.2
Flags: -std=c++17

Proposal:
Fix the parser to recognize empty attribute specifiers ([[ ]]) in array new
expressions.

Additional Notes:
Standard Compliance:
C++17 §10.6.1 allows empty attribute lists.
Clang and MSVC demonstrate correct behavior.

Compiler Explorer link: https://godbolt.org/z/azWxGdGn6

Reply via email to