Skip to content

Commit 131e878

Browse files
committed
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
1 parent 1a33294 commit 131e878

20 files changed

+30
-23
lines changed

clang/lib/AST/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3042,7 +3042,7 @@ StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
30423042
case Char32:
30433043
return "char32_t";
30443044
case NullPtr:
3045-
return "nullptr_t";
3045+
return "std::nullptr_t";
30463046
case Overload:
30473047
return "<overloaded function type>";
30483048
case BoundMember:

clang/test/AST/ast-dump-recovery.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ using Escape = decltype([] { return undef(); }());
250250
// CHECK-NEXT: `-RecoveryExpr {{.*}} '<dependent type>' contains-errors lvalue
251251
// CHECK-NEXT: `-InitListExpr
252252
// CHECK-NEXT: `-DesignatedInitExpr {{.*}} 'void'
253-
// CHECK-NEXT: `-CXXNullPtrLiteralExpr {{.*}} 'nullptr_t'
253+
// CHECK-NEXT: `-CXXNullPtrLiteralExpr {{.*}} 'std::nullptr_t'
254254
struct {
255255
int& abc;
256256
} NoCrashOnInvalidInitList = {

clang/test/Analysis/plist-diagnostics-template-record.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ int main() {
3838

3939
// CHECK: <string>Calling constructor for &apos;DivByZero&lt;int, float, double, 0&gt;&apos;</string>
4040
// CHECK: <string>Calling constructor for &apos;DivByZero&lt;char, float, double, 0&gt;&apos;</string>
41-
// CHECK: <string>Calling constructor for &apos;DivByZeroVariadic&lt;char, float, double, nullptr_t&gt;&apos;</string>
41+
// CHECK: <string>Calling constructor for &apos;DivByZeroVariadic&lt;char, float, double, std::nullptr_t&gt;&apos;</string>
4242

clang/test/CXX/drs/dr15xx.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ namespace dr1512 { // dr1512: 4
113113
}
114114

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

clang/test/CXX/drs/dr6xx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ namespace dr652 { // dr652: yes
590590
namespace dr654 { // dr654: sup 1423
591591
void f() {
592592
if (nullptr) {} // expected-warning {{implicit conversion of nullptr constant to 'bool'}}
593-
bool b = nullptr; // expected-error {{cannot initialize a variable of type 'bool' with an rvalue of type 'nullptr_t'}}
593+
bool b = nullptr; // expected-error {{cannot initialize a variable of type 'bool' with an rvalue of type 'std::nullptr_t'}}
594594
if (nullptr == 0) {}
595595
if (nullptr != 0) {}
596596
if (nullptr <= 0) {} // expected-error {{invalid operands}}

clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1-11.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ IP<nullptr> ip2;
2424
IP<get_nullptr()> ip3;
2525
IP<(int*)0> ip4;
2626
IP<np> ip5;
27-
IP<nonconst_np> ip5; // expected-error{{non-type template argument of type 'std::nullptr_t' (aka 'nullptr_t') is not a constant expression}} \
27+
IP<nonconst_np> ip5; // expected-error{{non-type template argument of type 'std::nullptr_t' is not a constant expression}} \
2828
// expected-note{{read of non-constexpr variable 'nonconst_np' is not allowed in a constant expression}}
2929
IP<(float*)0> ip6; // expected-error{{null non-type template argument of type 'float *' does not match template parameter of type 'int *'}}
3030
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
6262
NP<nullptr> np1;
6363
NP<np> np2;
6464
NP<get_nullptr()> np3;
65-
NP<0> np4; // expected-error{{null non-type template argument must be cast to template parameter type 'std::nullptr_t' (aka 'nullptr_t')}}
65+
NP<0> np4; // expected-error{{null non-type template argument must be cast to template parameter type 'std::nullptr_t'}}
6666
constexpr int i = 7;
6767
NP<i> np5; // expected-error{{non-type template argument of type 'const int' cannot be converted to a value of type 'std::nullptr_t'}}

clang/test/CXX/temp/temp.param/p10-2a.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ concept OneOf = (is_same_v<T, Ts> || ...);
9494
// expected-note@-5 {{and 'is_same_v<short, char>' evaluated to false}}
9595
// expected-note@-6 3{{because 'is_same_v<int, char [1]>' evaluated to false}}
9696
// expected-note@-7 3{{and 'is_same_v<int, char [2]>' evaluated to false}}
97-
// expected-note@-8 2{{because 'is_same_v<nullptr_t, char>' evaluated to false}}
98-
// expected-note@-9 2{{and 'is_same_v<nullptr_t, int>' evaluated to false}}
97+
// expected-note@-8 2{{because 'is_same_v<std::nullptr_t, char>' evaluated to false}}
98+
// expected-note@-9 2{{and 'is_same_v<std::nullptr_t, int>' evaluated to false}}
9999

100100
template<OneOf<char[1], char[2]> T, OneOf<int, long, char> U>
101101
// expected-note@-1 2{{because 'OneOf<char, char [1], char [2]>' evaluated to false}}

clang/test/CodeGenCXX/debug-info-template.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,10 @@ template void f1<t1 () volatile, t1 () const volatile, t1 () &, t1 () &&>();
238238
// CHECK: ![[RAW_FUNC_QUAL_REF_REF]] = !DISubroutineType(flags: DIFlagRValueReference, types: ![[RAW_FUNC_QUAL_LIST]])
239239

240240
} // namespace RawFuncQual
241+
242+
namespace Nullptr_t {
243+
template <typename T>
244+
void f1() {}
245+
template void f1<decltype(nullptr)>();
246+
// CHECK: !DISubprogram(name: "f1<std::nullptr_t>",
247+
} // namespace Nullptr_t

clang/test/OpenMP/task_affinity_messages.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int main(int argc, char **argv, char *env[]) {
6565
#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}}
6666
#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}}
6767
#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}}
68-
#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}}
68+
#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}}
6969
#pragma omp task affinity(iterator(vector *argc = 0:vector():argc):argc) // expected-error {{converting 'vector' to incompatible type 'vector *'}} expected-error {{expected expression}}
7070
foo();
7171
#pragma omp task affinity(iterator(i = 0:10, i = 0:10) : argv[i]) // expected-error {{redefinition of 'i'}} expected-note {{previous definition is here}}

clang/test/OpenMP/task_depend_messages.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int main(int argc, char **argv, char *env[]) {
7676
#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 '('}}
7777
#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 '('}}
7878
#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 ','}}
79-
#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}}
79+
#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}}
8080
#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 *'}}
8181
foo();
8282
#pragma omp task depend(iterator(unsigned argc = 0:10), in : argc) // omp45-error {{expected 'in', 'out', 'inout' or 'mutexinoutset' in OpenMP clause 'depend'}}

0 commit comments

Comments
 (0)