Skip to content

clang-21 regression: "enable_if attribute expression never produces a constant expression" when compiling LLVM in C++23 #150131

@vogelsgesang

Description

@vogelsgesang

The command

echo '#include "llvm/ADT/StringExtras.h"' | clang++-21 -x c++ - -std=c++23

fails with the compilation error

In file included from <stdin>:1:
In file included from ./llvm/include/llvm/ADT/StringExtras.h:19:
In file included from ./llvm/include/llvm/ADT/SmallString.h:18:
./llvm/include/llvm/ADT/StringRef.h:871:22: error: 'enable_if' attribute
      expression never produces a constant expression
  871 |         __attribute((enable_if(__builtin_strlen(Str) == N - 1,
      |                      ^
./llvm/include/llvm/ADT/StringExtras.h:150:34: note: in instantiation of
      function template specialization 'llvm::StringLiteral::StringLiteral<33UL>' requested here
  150 |   static constexpr StringLiteral Punctuations =
      |                                  ^
./llvm/include/llvm/ADT/StringRef.h:871:49: note: read of variable 'Str'
      whose value is not known
  871 |         __attribute((enable_if(__builtin_strlen(Str) == N - 1,
      |                                                 ^
./llvm/include/llvm/ADT/StringRef.h:867:42: note: declared here
  867 |     constexpr StringLiteral(const char (&Str)[N])
      |                                          ^
1 error generated.

Both clang-21 and the used LLVM source were taken from the 21.1.0-rc1 tag.

The same command works against clang++ version 20, as such this is a regression compared to clang-20.
(The issue also only appears for C++23, using C++20 on clang-21 works)

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++23clang:frontendLanguage frontend issues, e.g. anything involving "Sema"duplicateResolved as duplicateregression:21Regression in 21 release

    Type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions