Print nullptr_t namespace qualified within std::

This improves diagnostic (& important to me, DWARF) accuracy - otherwise
there could be ambiguities between "std::nullptr_t" and some user-defined
type that's /actually/ "nullptr_t" defined in the global namespace.

Differential Revision: https://reviews.llvm.org/D110044
This commit is contained in:
David Blaikie 2021-09-19 14:32:45 -07:00
parent 1a33294652
commit 131e878664
20 changed files with 30 additions and 23 deletions

View File

@ -3042,7 +3042,7 @@ StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
case Char32:
return "char32_t";
case NullPtr:
return "nullptr_t";
return "std::nullptr_t";
case Overload:
return "<overloaded function type>";
case BoundMember:

View File

@ -250,7 +250,7 @@ using Escape = decltype([] { return undef(); }());
// CHECK-NEXT: `-RecoveryExpr {{.*}} '<dependent type>' contains-errors lvalue
// CHECK-NEXT: `-InitListExpr
// CHECK-NEXT: `-DesignatedInitExpr {{.*}} 'void'
// CHECK-NEXT: `-CXXNullPtrLiteralExpr {{.*}} 'nullptr_t'
// CHECK-NEXT: `-CXXNullPtrLiteralExpr {{.*}} 'std::nullptr_t'
struct {
int& abc;
} NoCrashOnInvalidInitList = {

View File

@ -38,5 +38,5 @@ int main() {
// CHECK: <string>Calling constructor for &apos;DivByZero&lt;int, float, double, 0&gt;&apos;</string>
// CHECK: <string>Calling constructor for &apos;DivByZero&lt;char, float, double, 0&gt;&apos;</string>
// CHECK: <string>Calling constructor for &apos;DivByZeroVariadic&lt;char, float, double, nullptr_t&gt;&apos;</string>
// CHECK: <string>Calling constructor for &apos;DivByZeroVariadic&lt;char, float, double, std::nullptr_t&gt;&apos;</string>

View File

@ -113,7 +113,7 @@ namespace dr1512 { // dr1512: 4
}
#if __cplusplus >= 201103L
template<typename T> struct Wrap { operator T(); }; // expected-note 4{{converted to type 'nullptr_t'}} expected-note 4{{converted to type 'int *'}}
template<typename T> struct Wrap { operator T(); }; // expected-note 4{{converted to type 'std::nullptr_t'}} expected-note 4{{converted to type 'int *'}}
void test_overload() {
using nullptr_t = decltype(nullptr);
void(Wrap<nullptr_t>() == Wrap<nullptr_t>());
@ -127,7 +127,7 @@ namespace dr1512 { // dr1512: 4
// but then only convert as far as 'nullptr_t', which we then can't convert to 'int*'.
void(Wrap<nullptr_t>() == Wrap<int*>());
void(Wrap<nullptr_t>() != Wrap<int*>());
void(Wrap<nullptr_t>() < Wrap<int*>()); // expected-error {{invalid operands to binary expression ('Wrap<nullptr_t>' and 'Wrap<int *>')}}
void(Wrap<nullptr_t>() < Wrap<int*>()); // expected-error {{invalid operands to binary expression ('Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>') and 'Wrap<int *>')}}
void(Wrap<nullptr_t>() > Wrap<int*>()); // expected-error {{invalid operands}}
void(Wrap<nullptr_t>() <= Wrap<int*>()); // expected-error {{invalid operands}}
void(Wrap<nullptr_t>() >= Wrap<int*>()); // expected-error {{invalid operands}}

View File

@ -590,7 +590,7 @@ namespace dr652 { // dr652: yes
namespace dr654 { // dr654: sup 1423
void f() {
if (nullptr) {} // expected-warning {{implicit conversion of nullptr constant to 'bool'}}
bool b = nullptr; // expected-error {{cannot initialize a variable of type 'bool' with an rvalue of type 'nullptr_t'}}
bool b = nullptr; // expected-error {{cannot initialize a variable of type 'bool' with an rvalue of type 'std::nullptr_t'}}
if (nullptr == 0) {}
if (nullptr != 0) {}
if (nullptr <= 0) {} // expected-error {{invalid operands}}

View File

@ -24,7 +24,7 @@ IP<nullptr> ip2;
IP<get_nullptr()> ip3;
IP<(int*)0> ip4;
IP<np> ip5;
IP<nonconst_np> ip5; // expected-error{{non-type template argument of type 'std::nullptr_t' (aka 'nullptr_t') is not a constant expression}} \
IP<nonconst_np> ip5; // expected-error{{non-type template argument of type 'std::nullptr_t' is not a constant expression}} \
// expected-note{{read of non-constexpr variable 'nonconst_np' is not allowed in a constant expression}}
IP<(float*)0> ip6; // expected-error{{null non-type template argument of type 'float *' does not match template parameter of type 'int *'}}
IP<&tl> ip7; // expected-error{{non-type template argument of type 'int *' is not a constant expression}}
@ -62,6 +62,6 @@ template<std::nullptr_t np> struct NP { // expected-note 2{{template parameter i
NP<nullptr> np1;
NP<np> np2;
NP<get_nullptr()> np3;
NP<0> np4; // expected-error{{null non-type template argument must be cast to template parameter type 'std::nullptr_t' (aka 'nullptr_t')}}
NP<0> np4; // expected-error{{null non-type template argument must be cast to template parameter type 'std::nullptr_t'}}
constexpr int i = 7;
NP<i> np5; // expected-error{{non-type template argument of type 'const int' cannot be converted to a value of type 'std::nullptr_t'}}

View File

@ -94,8 +94,8 @@ concept OneOf = (is_same_v<T, Ts> || ...);
// expected-note@-5 {{and 'is_same_v<short, char>' evaluated to false}}
// expected-note@-6 3{{because 'is_same_v<int, char [1]>' evaluated to false}}
// expected-note@-7 3{{and 'is_same_v<int, char [2]>' evaluated to false}}
// expected-note@-8 2{{because 'is_same_v<nullptr_t, char>' evaluated to false}}
// expected-note@-9 2{{and 'is_same_v<nullptr_t, int>' evaluated to false}}
// expected-note@-8 2{{because 'is_same_v<std::nullptr_t, char>' evaluated to false}}
// expected-note@-9 2{{and 'is_same_v<std::nullptr_t, int>' evaluated to false}}
template<OneOf<char[1], char[2]> T, OneOf<int, long, char> U>
// expected-note@-1 2{{because 'OneOf<char, char [1], char [2]>' evaluated to false}}

View File

@ -238,3 +238,10 @@ template void f1<t1 () volatile, t1 () const volatile, t1 () &, t1 () &&>();
// CHECK: ![[RAW_FUNC_QUAL_REF_REF]] = !DISubroutineType(flags: DIFlagRValueReference, types: ![[RAW_FUNC_QUAL_LIST]])
} // namespace RawFuncQual
namespace Nullptr_t {
template <typename T>
void f1() {}
template void f1<decltype(nullptr)>();
// CHECK: !DISubprogram(name: "f1<std::nullptr_t>",
} // namespace Nullptr_t

View File

@ -65,7 +65,7 @@ int main(int argc, char **argv, char *env[]) {
#pragma omp task affinity(iterator(unsigned argc: // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected '=' in iterator specifier}} expected-error 2 {{expected expression}} expected-error {{expected ',' or ')' after iterator specifier}} expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected expression}}
#pragma omp task affinity(iterator(unsigned argc = // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error 2 {{expected expression}} expected-error {{expected ',' or ')' after iterator specifier}} expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected expression}}
#pragma omp task affinity(iterator(vector argc = 0:2):argc) // expected-error {{expected integral or pointer type as the iterator-type, not 'vector'}} expected-error {{expected expression}}
#pragma omp task affinity(iterator(vector *argc = nullptr:nullptr+2:0):argc) // expected-error {{invalid operands to binary expression ('nullptr_t' and 'int')}} expected-error {{iterator step expression 0 evaluates to 0}} expected-error {{expected expression}}
#pragma omp task affinity(iterator(vector *argc = nullptr:nullptr+2:0):argc) // expected-error {{invalid operands to binary expression ('std::nullptr_t' and 'int')}} expected-error {{iterator step expression 0 evaluates to 0}} expected-error {{expected expression}}
#pragma omp task affinity(iterator(vector *argc = 0:vector():argc):argc) // expected-error {{converting 'vector' to incompatible type 'vector *'}} expected-error {{expected expression}}
foo();
#pragma omp task affinity(iterator(i = 0:10, i = 0:10) : argv[i]) // expected-error {{redefinition of 'i'}} expected-note {{previous definition is here}}

View File

@ -76,7 +76,7 @@ int main(int argc, char **argv, char *env[]) {
#pragma omp task depend(iterator(unsigned argc: // expected-error {{expected ')'}} omp45-error {{expected 'in', 'out', 'inout' or 'mutexinoutset' in OpenMP clause 'depend'}} expected-warning {{missing ':' after dependency type - ignoring}} expected-note {{to match this '('}} omp50-error {{expected '=' in iterator specifier}} omp50-error 2 {{expected expression}} omp50-error {{expected ',' or ')' after iterator specifier}} omp50-error {{expected ')'}} omp50-error {{expected depend modifier(iterator) or 'in', 'out', 'inout', 'mutexinoutset' or 'depobj' in OpenMP clause 'depend'}} omp50-error {{expected ','}} omp50-note {{to match this '('}}
#pragma omp task depend(iterator(unsigned argc = // expected-error {{expected ')'}} omp45-error {{expected 'in', 'out', 'inout' or 'mutexinoutset' in OpenMP clause 'depend'}} expected-warning {{missing ':' after dependency type - ignoring}} expected-note {{to match this '('}} omp50-error 2 {{expected expression}} omp50-error {{expected ',' or ')' after iterator specifier}} omp50-error {{expected ')'}} omp50-error {{expected depend modifier(iterator) or 'in', 'out', 'inout', 'mutexinoutset' or 'depobj' in OpenMP clause 'depend'}} omp50-error {{expected ','}} omp50-note {{to match this '('}}
#pragma omp task depend(iterator(vector argc = 0:2):argc) // omp45-error {{expected 'in', 'out', 'inout' or 'mutexinoutset' in OpenMP clause 'depend'}} omp50-error {{expected integral or pointer type as the iterator-type, not 'vector'}} omp50-error {{expected depend modifier(iterator) or 'in', 'out', 'inout', 'mutexinoutset' or 'depobj' in OpenMP clause 'depend'}} omp50-error {{expected ','}}
#pragma omp task depend(iterator(vector *argc = nullptr:nullptr+2:0), in:argc) // omp45-error {{expected 'in', 'out', 'inout' or 'mutexinoutset' in OpenMP clause 'depend'}} omp50-error {{invalid operands to binary expression ('nullptr_t' and 'int')}} omp50-error {{iterator step expression 0 evaluates to 0}}
#pragma omp task depend(iterator(vector *argc = nullptr:nullptr+2:0), in:argc) // omp45-error {{expected 'in', 'out', 'inout' or 'mutexinoutset' in OpenMP clause 'depend'}} omp50-error {{invalid operands to binary expression ('std::nullptr_t' and 'int')}} omp50-error {{iterator step expression 0 evaluates to 0}}
#pragma omp task depend(iterator(vector *argc = 0:vector():argc), in:argc) // omp45-error {{expected 'in', 'out', 'inout' or 'mutexinoutset' in OpenMP clause 'depend'}} omp50-error {{converting 'vector' to incompatible type 'vector *'}}
foo();
#pragma omp task depend(iterator(unsigned argc = 0:10), in : argc) // omp45-error {{expected 'in', 'out', 'inout' or 'mutexinoutset' in OpenMP clause 'depend'}}

View File

@ -130,7 +130,7 @@ ptrdiff_t subtract_pointers4(int *a, char *b) {
#ifdef __cplusplus
ptrdiff_t subtract_pointers5() {
// expected-error@+1 {{at least one argument of MTE builtin function must be a pointer ('nullptr_t', 'nullptr_t' invalid)}}
// expected-error@+1 {{at least one argument of MTE builtin function must be a pointer ('std::nullptr_t', 'std::nullptr_t' invalid)}}
return __arm_mte_ptrdiff(nullptr, nullptr);
}
#endif

View File

@ -15,6 +15,6 @@ int main() {
#endif
#ifdef __cplusplus
printf("%p", nullptr); // expected-warning {{format specifies type 'void *' but the argument has type 'nullptr_t'}}
printf("%p", nullptr); // expected-warning {{format specifies type 'void *' but the argument has type 'std::nullptr_t'}}
#endif
}

View File

@ -86,7 +86,7 @@ const int *ptr = nullptr;
void f() noexcept(sizeof(char[2])); // expected-error {{noexcept specifier argument evaluates to 2, which cannot be narrowed to type 'bool'}}
void g() noexcept(sizeof(char));
void h() noexcept(ptr); // expected-error {{conversion from 'const int *' to 'bool' is not allowed in a converted constant expression}}
void i() noexcept(nullptr); // expected-error {{conversion from 'nullptr_t' to 'bool' is not allowed in a converted constant expression}}
void i() noexcept(nullptr); // expected-error {{conversion from 'std::nullptr_t' to 'bool' is not allowed in a converted constant expression}}
void j() noexcept(0);
void k() noexcept(1);
void l() noexcept(2); // expected-error {{noexcept specifier argument evaluates to 2, which cannot be narrowed to type 'bool'}}

View File

@ -735,7 +735,7 @@ const int *ptr;
struct S {
explicit(sizeof(char[2])) S(char); // expected-error {{explicit specifier argument evaluates to 2, which cannot be narrowed to type 'bool'}}
explicit(ptr) S(long); // expected-error {{conversion from 'const int *' to 'bool' is not allowed in a converted constant expression}}
explicit(nullptr) S(int); // expected-error {{conversion from 'nullptr_t' to 'bool' is not allowed in a converted constant expression}}
explicit(nullptr) S(int); // expected-error {{conversion from 'std::nullptr_t' to 'bool' is not allowed in a converted constant expression}}
explicit(42L) S(int, int); // expected-error {{explicit specifier argument evaluates to 42, which cannot be narrowed to type 'bool'}}
explicit(sizeof(char)) S();
explicit(0) S(char, char);

View File

@ -15,7 +15,7 @@ class X {
// Nullability applies to all pointer types.
typedef int (X::* _Nonnull member_function_type_1)(int);
typedef int X::* _Nonnull member_data_type_1;
typedef nullptr_t _Nonnull nonnull_nullptr_t; // expected-error{{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'nullptr_t'}}
typedef nullptr_t _Nonnull nonnull_nullptr_t; // expected-error{{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'nullptr_t' (aka 'std::nullptr_t')}}
// Nullability can move into member pointers (this is suppressing a warning).
typedef _Nonnull int (X::* member_function_type_2)(int);
@ -26,7 +26,7 @@ typedef _Nonnull int X::* member_data_type_2;
template<typename T>
struct AddNonNull {
typedef _Nonnull T type; // expected-error{{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'int'}}
// expected-error@-1{{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'nullptr_t'}}
// expected-error@-1{{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'std::nullptr_t'}}
};
typedef AddNonNull<int *>::type nonnull_int_ptr_1;

View File

@ -57,7 +57,7 @@ nullptr_t f(nullptr_t null)
o2(nullptr); // expected-error {{ambiguous}}
// nullptr is an rvalue, null is an lvalue
(void)&nullptr; // expected-error {{cannot take the address of an rvalue of type 'nullptr_t'}}
(void)&nullptr; // expected-error {{cannot take the address of an rvalue of type 'std::nullptr_t'}}
nullptr_t *pn = &null;
// You can reinterpret_cast nullptr to an integer.

View File

@ -73,7 +73,7 @@ using BT = B<char, 'x'>;
// CHECK: `-CXXDeductionGuideDecl {{.*}} 'auto (X<nullptr, 'x'>) -> B<char, 'x'>'
// CHECK: |-TemplateArgument type 'char'
// CHECK: |-TemplateArgument integral 120
// CHECK: |-TemplateArgument type 'nullptr_t'
// CHECK: |-TemplateArgument type 'std::nullptr_t'
// CHECK: |-TemplateArgument nullptr
// CHECK: `-ParmVarDecl {{.*}} 'X<nullptr, 'x'>':'X<nullptr, 'x'>'
// CHECK: FunctionProtoType {{.*}} 'auto (X<W, V>) -> B<T, V>' dependent trailing_return

View File

@ -313,7 +313,7 @@ namespace nullptr_deduction {
}
template<template<typename T, T> class X, typename T, int *P>
void f0(X<T, P>) {} // expected-note {{deduced non-type template argument does not have the same type as the corresponding template parameter ('nullptr_t' vs 'int *')}}
void f0(X<T, P>) {} // expected-note {{deduced non-type template argument does not have the same type as the corresponding template parameter ('std::nullptr_t' vs 'int *')}}
void h0() {
f0(X<int*, nullptr>());
f0(X<nullptr_t, nullptr>()); // expected-error {{no matching function}}

View File

@ -146,5 +146,5 @@ namespace PR42513_comment3 {
template<typename X> struct T { friend auto f(X*) { return nullptr; } };
struct X1 { friend auto f(X1*); };
template struct T<X1>;
int n = f((X1*)nullptr); // expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'nullptr_t'}}
int n = f((X1*)nullptr); // expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'std::nullptr_t'}}
}

View File

@ -489,7 +489,7 @@ namespace anon_union_default_member_init {
namespace PR45000 {
template <typename T>
void f(int x = [](T x = nullptr) -> int { return x; }());
// expected-error@-1 {{cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'}}
// expected-error@-1 {{cannot initialize a parameter of type 'int' with an rvalue of type 'std::nullptr_t'}}
// expected-note@-2 {{passing argument to parameter 'x' here}}
void g() { f<int>(); }