[clang] No longer add enumeration constants to the wrong scope (PR #134998)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 9 11:46:59 PDT 2025


================
@@ -5585,6 +5585,18 @@ SourceRange EnumConstantDecl::getSourceRange() const {
   return SourceRange(getLocation(), End);
 }
 
+bool EnumConstantDecl::isOutOfLine() const {
+  if (Decl::isOutOfLine())
+    return true;
+
+  // In C++, if the enumeration is out of line, the enumeration constants are
+  // also out of line.
+  if (getLangOpts().CPlusPlus)
----------------
AaronBallman wrote:

Agreed that C has no way to spell this and from my looking, it seems like every place which calls `isOutOfLine()` is a C++-specific code path, but many times it seems to be accidental. For example, we have several uses that are guarded on whether something is a static data member, which is a C++-only concept, rather than guarding on C++ itself. As C integrates more C++ features, I worry that we'll end up calling this in C code as well, so that's a defensive measure. It technically can be removed, but I'm not certain we want to remove it, WDYT?

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


More information about the cfe-commits mailing list