[clang] [clang-cl] Add support for [[msvc::constexpr]] C++11 attribute (PR #71300)

Richard Dzenis via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 8 12:36:22 PST 2023


================
@@ -2884,6 +2884,12 @@ def warn_cxx11_compat_constexpr_body_multiple_return : Warning<
   InGroup<CXXPre14Compat>, DefaultIgnore;
 def note_constexpr_body_previous_return : Note<
   "previous return statement is here">;
+def err_ms_constexpr_not_distinct : Error<
+  "[[msvc::constexpr]] cannot be applied to a %select{constexpr|consteval}0 function %1">;
----------------
RIscRIpt wrote:

tl;dr afterall I would keep it as-is.

Sorry, I overestimated this possibility.

> attribute 'msvc::constexpr' cannot be applied to the virtual function %1

This could be replaced with existing diagnostic
```
def err_constexpr_virtual : Error<"virtual function cannot be constexpr">;
```

However, two other variants of this new diagnostic:

> attribute 'msvc::constexpr' cannot be applied to the constexpr function %1
> attribute 'msvc::constexpr' cannot be applied to the consteval function %1

Are not easily replaceable. The most similar diagnostic I was able to find was:

```
def err_invalid_decl_spec_combination : Error<
  "cannot combine with previous '%0' declaration specifier">;
```

But, using this diagnostic, warnings are not consistent:

```
/home/richard/projects/llvm-project/clang/test/SemaCXX/ms-constexpr-invalid.cpp:10:3: error: cannot combine with previous 'constexpr' declaration specifier
   10 | [[msvc::constexpr]] constexpr void f1() {}
      |   ^~~~
```

`constexpr` comes after `[[msvc::constexpr]]`, but the message implies that `constexpr` came first.

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


More information about the cfe-commits mailing list