[clang] [clang] adds explanation for why std::is_const is false (PR #235587)

Matthias Wippich via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 27 19:40:47 PDT 2026


================
@@ -374,6 +397,37 @@ static_assert(std::is_abstract_v<int&>);
 // expected-note at -1 {{because it is a reference type}} \
 // expected-note at -1 {{because it is not a struct or class type}}
 
+static_assert(!std::is_const<int>::value);
+
+static_assert(std::is_const<void()>::value);
+// expected-error-re at -1 {{static assertion failed due to requirement 'std::{{.*}}is_const<void ()>::value'}} \
+// expected-note at -1 {{'void ()' is not const}} \
+// expected-note at -1 {{because it is a function type}}
----------------
Tsche wrote:

The second note you emit here ("because it is a function type") seems misleading to me. It's not `const` because.. well.. the thing you gave it isn't `const`.

In C++ there are [Abominable Function Types](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0172r0.html), which do occasionally pop up in generic programs. Here's some relevant standardese: https://eel.is/c++draft/dcl.fct#11

I would like to see a test for something along the lines of
```cpp
typedef int FIC(int) const;
static_assert(std::is_const<FIC>::value); //expected to fail
```
here. I believe this is supposed to return `false` because of https://eel.is/c++draft/basic.type.qualifier#1.sentence-3

Therefore, I suggest the note to be changed to something along the lines of "function types are always cv-unqualified" (although.. a bit more de-standardesed perhaps?).


https://github.com/llvm/llvm-project/pull/235587


More information about the cfe-commits mailing list