[PATCH] D98087: [clang] Fix constrained decltype(auto) deduction
Matheus Izvekov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 5 15:51:37 PST 2021
mizvekov created this revision.
mizvekov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Prior to this fix, constrained decltype(auto) behaves exactly the same
as constrained regular auto.
This fixes it so it deduces like decltype(auto).
Signed-off-by: Matheus Izvekov <mizvekov at gmail.com>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D98087
Files:
clang/lib/Sema/SemaType.cpp
clang/test/CXX/dcl/dcl.fct/p17.cpp
clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
clang/test/Parser/cxx2a-placeholder-type-constraint.cpp
Index: clang/test/Parser/cxx2a-placeholder-type-constraint.cpp
===================================================================
--- clang/test/Parser/cxx2a-placeholder-type-constraint.cpp
+++ clang/test/Parser/cxx2a-placeholder-type-constraint.cpp
@@ -23,13 +23,13 @@
{C<> decltype(auto) a = 1;}
{C<int> decltype(auto) a = 1;}
{const C<> decltype(auto) &a = 1;} // expected-error{{'decltype(auto)' cannot be combined with other type specifiers}}
- // expected-error at -1{{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}}
+ // expected-error at -1{{cannot form reference to 'decltype(auto)'}}
{const C<int> decltype(auto) &a = 1;} // expected-error{{'decltype(auto)' cannot be combined with other type specifiers}}
- // expected-error at -1{{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}}
+ // expected-error at -1{{cannot form reference to 'decltype(auto)'}}
{C a = 1;}
// expected-error at -1{{expected 'auto' or 'decltype(auto)' after concept name}}
{C decltype a19 = 1;}
// expected-error at -1{{expected '('}}
{C decltype(1) a20 = 1;}
// expected-error at -1{{expected 'auto' or 'decltype(auto)' after concept name}}
-}
\ No newline at end of file
+}
Index: clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
===================================================================
--- clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
+++ clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
@@ -1,4 +1,6 @@
// RUN: %clang_cc1 -std=c++2a -verify %s
+template<typename T, typename U> constexpr bool is_same_v = false;
+template<typename T> constexpr bool is_same_v<T, T> = true;
template<typename T, unsigned size>
concept LargerThan = sizeof(T) > size;
@@ -41,4 +43,22 @@
auto test6() -> Large auto { return 1; }
X::Small auto test7() { return 'a'; }
-X::SmallerThan<5> auto test8() { return 10; }
\ No newline at end of file
+X::SmallerThan<5> auto test8() { return 10; }
+
+namespace {
+ int a = 0;
+ int &b = a;
+ template <class T> concept True = true;
+
+ True auto c = a;
+ static_assert(is_same_v<decltype(c), int>);
+
+ True auto d = b;
+ static_assert(is_same_v<decltype(d), int>);
+
+ True decltype(auto) e = a;
+ static_assert(is_same_v<decltype(e), int>);
+
+ True decltype(auto) f = b;
+ static_assert(is_same_v<decltype(f), int&>);
+}
Index: clang/test/CXX/dcl/dcl.fct/p17.cpp
===================================================================
--- clang/test/CXX/dcl/dcl.fct/p17.cpp
+++ clang/test/CXX/dcl/dcl.fct/p17.cpp
@@ -186,7 +186,7 @@
static_assert(is_same_v<decltype(f9(i, c)), void>);
// expected-error at -1{{no matching}}
static_assert(is_same_v<decltype(f9(i, i, ci)), void>);
- void f10(C decltype(auto) x);
+ void f10(C decltype(auto) x); // expected-error{{decltype(auto)' not allowed in function prototype}}
auto f11 = [] (C auto x) { };
// expected-note at -1{{candidate template ignored}} expected-note at -1{{because}}
static_assert(is_same_v<decltype(f11(1)), void>);
@@ -238,7 +238,7 @@
static_assert(is_same_v<decltype(f20(i, c)), void>);
// expected-error at -1{{no matching}}
static_assert(is_same_v<decltype(f20(c, c, cc)), void>);
- void f21(C2<char> decltype(auto) x);
+ void f21(C2<char> decltype(auto) x); // expected-error{{decltype(auto)' not allowed in function prototype}}
auto f22 = [] (C2<char> auto x) { };
// expected-note at -1{{candidate template ignored}} expected-note at -1{{because}}
static_assert(is_same_v<decltype(f22(1)), void>);
Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1269,11 +1269,10 @@
llvm::SmallVector<TemplateArgument, 8> TemplateArgs;
for (auto &ArgLoc : TemplateArgsInfo.arguments())
TemplateArgs.push_back(ArgLoc.getArgument());
- return S.Context.getAutoType(QualType(), AutoTypeKeyword::Auto, false,
- /*IsPack=*/false,
- cast<ConceptDecl>(TemplateId->Template.get()
- .getAsTemplateDecl()),
- TemplateArgs);
+ return S.Context.getAutoType(
+ QualType(), AutoKW, false, /*IsPack=*/false,
+ cast<ConceptDecl>(TemplateId->Template.get().getAsTemplateDecl()),
+ TemplateArgs);
}
/// Convert the specified declspec to the appropriate type
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98087.328676.patch
Type: text/x-patch
Size: 4462 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210305/55aa7621/attachment-0001.bin>
More information about the cfe-commits
mailing list