[clang] [clang] add `-fimplicit-constexpr` flag (PR #136436)

via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 19 09:53:24 PDT 2025


================
@@ -10163,6 +10163,16 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
     }
 
     ConstexprSpecKind ConstexprKind = D.getDeclSpec().getConstexprSpecifier();
+
+    // Clang's option -fimplicit-constexpr will make functions without constexpr
+    // or consteval specifier implicitly constexpr (compatibility with GCC.)
+    if (ConstexprKind == ConstexprSpecKind::Unspecified &&
+        getLangOpts().ImplicitConstexpr) {
----------------
Sirraide wrote:

One thing worth pointing out is that GCC’s `-fimplicit-constexpr` only affects `inline` functions. There are probably reasons for that but I don’t know if they are an implementation detail or if the GCC devs had good reasons why this wouldn’t be desirable for non-`inline` functions.

I personally think the flag isn’t that useful if it requires `inline`, because if you have to write `inline` anyway, then you might as well just write `constexpr` instead.

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


More information about the cfe-commits mailing list