llvm-project/clang/test/Parser/enableif-attr.cpp
Oleksandr T. dfc0abd325
[Clang] prevent crash in early parsing of enable_if for C function declarators with identifier-list parameters (#174017)
Fixes #173826

---

This patch resolves an issue where Clang could crash while parsing the
`enable_if` attribute on C function declarators with identifier-list
parameters.

In C, identifier-list function declarators use parameter identifiers
rather than full parameter declarations, as specified by the C spec.
Since `enable_if` is parsed early to participate in redeclaration checks


0f3a9f658a/clang/lib/Parse/ParseDecl.cpp (L674-L675)

the parser could encounter such identifiers before their parameter
declarations exist and incorrectly assume they were already formed,
leading to an assertion failure.

This change makes the early `enable_if` parsing path handle parameters
that have not yet been declared, preventing the crash while preserving
existing behavior for well-formed function prototypes.
2026-01-06 21:38:41 +02:00

5 lines
336 B
C++

// RUN: %clang_cc1 -x c -fsyntax-only -verify %s
void f1(x) __attribute__((enable_if(1, ""))); // expected-error {{a parameter list without types is only allowed in a function definition}}
void f2(x, y) __attribute__((enable_if(1, ""))); // expected-error {{a parameter list without types is only allowed in a function definition}}