[clang] [Clang][NFC] Adding note on details that are not immediately obvious (PR #138349)

Shafik Yaghmour via cfe-commits cfe-commits at lists.llvm.org
Fri May 2 14:39:09 PDT 2025


https://github.com/shafik created https://github.com/llvm/llvm-project/pull/138349

This code was flagged by static analysis. It was a false positive but the reason why this code is valid is subtle and folks refactoring this code in the future could easily miss it.

>From 48a5b4a859c78fbc36947323fe7fda2abd6579b1 Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour <shafik.yaghmour at intel.com>
Date: Thu, 1 May 2025 22:33:14 -0700
Subject: [PATCH] [Clang][NFC] Adding note on details that are not immediately
 obvious

This code was flagged by static analysis. It was a false positive but the reason
why this code is valid is subtle and folks refactoring this code in the future
could easily miss it.
---
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 0e81804f8c1e7..ca5db61afbd2e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1137,6 +1137,9 @@ void Sema::PrintInstantiationStack(InstantiationContextDiagFuncRef DiagFunc) {
       // FIXME: For synthesized functions that are not defaulted,
       // produce a note.
       auto *FD = dyn_cast<FunctionDecl>(Active->Entity);
+      // Note: if FD is nullptr currently setting DFK to DefaultedFunctionKind()
+      // will ensure that DFK.isComparison() is false. This is important because
+      // we will uncondtionally dereference FD in the else if.
       DefaultedFunctionKind DFK =
           FD ? getDefaultedFunctionKind(FD) : DefaultedFunctionKind();
       if (DFK.isSpecialMember()) {



More information about the cfe-commits mailing list