[clang] [clang-cl] Add support for [[msvc::constexpr]] C++11 attribute (PR #71300)
Richard Dzenis via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 13 10:49:15 PST 2023
================
@@ -7337,6 +7337,27 @@ static void handleDeclspecThreadAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
D->addAttr(::new (S.Context) ThreadAttr(S.Context, AL));
}
+static void handleMSConstexprAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+ if (!S.getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2022_3)) {
+ S.Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
+ << AL << AL.getRange();
+ return;
+ }
+ auto *FD = cast<FunctionDecl>(D);
+ if (FD->isConstexprSpecified() || FD->isConsteval()) {
+ S.Diag(AL.getLoc(), diag::err_ms_constexpr_not_distinct)
+ << FD->isConsteval() << FD;
+ return;
+ }
+ if (auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
----------------
RIscRIpt wrote:
Prior to C++20 `constexpr` functions were not allowed to be `virtual` [cppreference](https://en.cppreference.com/w/cpp/language/constexpr).
I know this is an attribute, but this matches MSVC behavior: https://godbolt.org/z/snn6c1EW7
https://github.com/llvm/llvm-project/pull/71300
More information about the cfe-commits
mailing list