[clang] [clang] Fix -Wdangling false negative regressions caused by 117315 (PR #118088)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 29 05:03:13 PST 2024


================
@@ -258,9 +258,27 @@ template <typename T> static bool isRecordWithAttr(QualType Type) {
   auto *RD = Type->getAsCXXRecordDecl();
   if (!RD)
     return false;
+  // Generally, if a primary template class declaration is annotated with an
+  // attribute, all its specializations generated from template instantiations
+  // should inherit the attribute.
+  //
+  // However, since lifetime analysis occurs during parsing, we may encounter
+  // cases where a full definition of the specialization is not required. In
+  // such cases, the specialization declaration remains incomplete and lacks the
+  // attribute. Therefore, we fall back to checking the primary template class.
+  //
+  // Note: it is possible for a specialization declaration to have an attribute
+  // even if the primary template does not.
+  //
+  // FIXME: What if the primary template and explicit specialization
+  // declarations have conflicting attributes? We should consider diagnosing
+  // this scenario.
----------------
usx95 wrote:

I think this looks fine for now. Merging seems to be right thing for now.
Although merging Owner and Pointer seems problematic though which we should diagnose. Let's revisit if there is a need.

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


More information about the cfe-commits mailing list