hliao created this revision.
hliao added reviewers: rjmccall, tra, yaxunl.
Herald added subscribers: cfe-commits, kristof.beyls, javed.absar.
Herald added a project: clang.

- Non-null checking is triggered during prototype substitution from a template 
instantiation, if expressions in `decltype` contains nullptr chcking. Skip 
non-null checking in that case as the protype is not finalized yet. Also, the 
nullptr checking in `decltype` is only used for type inspection instead of 
codegen. Ignoring that is harmless.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D59900

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaTemplate/decltype.cpp


Index: clang/test/SemaTemplate/decltype.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaTemplate/decltype.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// no crash & no diag
+
+// expected-no-diagnostics
+template <typename T>
+auto foo(T x) -> decltype((x == nullptr), *x) {
+  return *x;
+}
+
+void bar() {
+  foo(new int);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -11592,6 +11592,9 @@
       }
 
       if (const auto *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
+        // Skip function template not specialized yet.
+        if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate)
+          return;
         auto ParamIter = llvm::find(FD->parameters(), PV);
         assert(ParamIter != FD->param_end());
         unsigned ParamNo = std::distance(FD->param_begin(), ParamIter);


Index: clang/test/SemaTemplate/decltype.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaTemplate/decltype.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// no crash & no diag
+
+// expected-no-diagnostics
+template <typename T>
+auto foo(T x) -> decltype((x == nullptr), *x) {
+  return *x;
+}
+
+void bar() {
+  foo(new int);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -11592,6 +11592,9 @@
       }
 
       if (const auto *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
+        // Skip function template not specialized yet.
+        if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate)
+          return;
         auto ParamIter = llvm::find(FD->parameters(), PV);
         assert(ParamIter != FD->param_end());
         unsigned ParamNo = std::distance(FD->param_begin(), ParamIter);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to