tzik created this revision.
tzik added reviewers: rsmith, thakis.
Herald added a subscriber: cfe-commits.

Clang used to pass the base lvalue of a non-type template parameter
to the template instantiation phase when the base part is __uuidof
and it's running in C++17 mode.
However, that drops its LValuePath, and unintentionally transforms
`&__uuidof(...)` to `__uuidof(...)`.

This CL fixes that by passing whole expr. Fixes PR24986.


Repository:
  rC Clang

https://reviews.llvm.org/D46820

Files:
  lib/Sema/SemaTemplate.cpp
  test/SemaCXX/PR24986.cpp


Index: test/SemaCXX/PR24986.cpp
===================================================================
--- /dev/null
+++ test/SemaCXX/PR24986.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -fms-extensions -std=c++17 %s
+
+typedef struct _GUID {} GUID;
+
+template <const GUID* p>
+void f() {
+  const GUID* q = p;
+}
+
+void g() {
+  f<&__uuidof(0)>();
+}
Index: lib/Sema/SemaTemplate.cpp
===================================================================
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -6197,7 +6197,7 @@
       // -- a predefined __func__ variable
       if (auto *E = Value.getLValueBase().dyn_cast<const Expr*>()) {
         if (isa<CXXUuidofExpr>(E)) {
-          Converted = TemplateArgument(const_cast<Expr*>(E));
+          Converted = TemplateArgument(ArgResult.get());
           break;
         }
         Diag(Arg->getLocStart(), diag::err_template_arg_not_decl_ref)


Index: test/SemaCXX/PR24986.cpp
===================================================================
--- /dev/null
+++ test/SemaCXX/PR24986.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -fms-extensions -std=c++17 %s
+
+typedef struct _GUID {} GUID;
+
+template <const GUID* p>
+void f() {
+  const GUID* q = p;
+}
+
+void g() {
+  f<&__uuidof(0)>();
+}
Index: lib/Sema/SemaTemplate.cpp
===================================================================
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -6197,7 +6197,7 @@
       // -- a predefined __func__ variable
       if (auto *E = Value.getLValueBase().dyn_cast<const Expr*>()) {
         if (isa<CXXUuidofExpr>(E)) {
-          Converted = TemplateArgument(const_cast<Expr*>(E));
+          Converted = TemplateArgument(ArgResult.get());
           break;
         }
         Diag(Arg->getLocStart(), diag::err_template_arg_not_decl_ref)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to