]> granicus.if.org Git - clang/commitdiff
Fix __uuidof handling on non-type template parameter in C++17
authorNico Weber <nicolasweber@gmx.de>
Thu, 17 May 2018 15:26:37 +0000 (15:26 +0000)
committerNico Weber <nicolasweber@gmx.de>
Thu, 17 May 2018 15:26:37 +0000 (15:26 +0000)
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.

https://reviews.llvm.org/D46820?id=146557
Patch from Taiju Tsuiki <tzik@chromium.org>!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@332614 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplate.cpp
test/SemaCXX/ms-uuid.cpp

index a5f6b3f026f1543bc56c48763dcdc70b8c57abe9..8f316024cc6256f9b9dbaf429ecf09e4a78f7c91 100644 (file)
@@ -6245,7 +6245,7 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
       // -- 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 c26ea688e373f6a04d0e446e9dfc003a50f700fb..624ac0541db46721c02ef5f003ebe4caf786ee4f 100644 (file)
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s -Wno-deprecated-declarations
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify -fms-extensions %s -Wno-deprecated-declarations
 
 typedef struct _GUID {
   unsigned long Data1;
@@ -92,4 +93,16 @@ class __declspec(uuid("000000A0-0000-0000-C000-000000000049"))
 // the previous case).
 [uuid("000000A0-0000-0000-C000-000000000049"),
  uuid("000000A0-0000-0000-C000-000000000049")] class C10;
+
+template <const GUID* p>
+void F1() {
+  // Regression test for PR24986. The given GUID should just work as a pointer.
+  const GUID* q = p;
+}
+
+void F2() {
+  // The UUID should work for a non-type template parameter.
+  F1<&__uuidof(C1)>();
+}
+
 }