[PATCH] D22844: Tweak the diagnostic machinery to emit a NamedDecl's type, instead of empty quotes, if it represents an unnamed TypeDecl.
Faisal Vali via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 26 19:47:18 PDT 2016
faisalv created this revision.
faisalv added a reviewer: rsmith.
faisalv added a subscriber: cfe-commits.
Currently the following code triggers diagnostics that match:
auto L = []{ }; //expected-note{{'' is not literal}}
constexpr int f(decltype(L)) { return 0; } //expected-error{{not a literal type}}
After applying this patch the diagnostics match:
auto L = []{ }; //expected-note{{'(lambda at <source-info>)' is not literal}}
As encouraged by Richard during his review of: https://reviews.llvm.org/D22662 .
https://reviews.llvm.org/D22844
Files:
include/clang/AST/Decl.h
lib/AST/ASTContext.cpp
test/SemaCXX/constant-expression-cxx11.cpp
Index: test/SemaCXX/constant-expression-cxx11.cpp
===================================================================
--- test/SemaCXX/constant-expression-cxx11.cpp
+++ test/SemaCXX/constant-expression-cxx11.cpp
@@ -1137,7 +1137,22 @@
return B().x == k; // expected-note {{non-literal type 'PR11595::B' cannot be used in a constant expression}}
}
}
+namespace NonLiteralTypes {
+auto L = [] {
+ return []{}; //expected-note{{lambda at}}
+};
+
+constexpr int f(decltype(L()) l) { return 0; } //expected-error{{not a literal type}}
+
+auto U = [] {
+ union { volatile int I; } obj; //expected-note{{anonymous union at}}
+ return obj;
+};
+constexpr int f(decltype(U()) l) { return 0; } //expected-error{{not a literal type}}
+
+}
+
namespace ExprWithCleanups {
struct A { A(); ~A(); int get(); };
constexpr int get(bool FromA) { return FromA ? A().get() : 1; }
Index: lib/AST/ASTContext.cpp
===================================================================
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -3276,7 +3276,12 @@
return QualType(Decl->TypeForDecl, 0);
}
-
+namespace clang {
+ QualType getTypeDeclTypeFromASTContext(const TypeDecl *T,
+ ASTContext &Ctx) {
+ return Ctx.getTypeDeclType(T);
+ }
+}
/// getTypedefType - Return the unique reference to the type for the
/// specified typedef name decl.
QualType
Index: include/clang/AST/Decl.h
===================================================================
--- include/clang/AST/Decl.h
+++ include/clang/AST/Decl.h
@@ -3799,18 +3799,39 @@
static bool classofKind(Kind K) { return K == Empty; }
};
+
+
+
/// Insertion operator for diagnostics. This allows sending NamedDecl's
/// into a diagnostic with <<.
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
const NamedDecl* ND) {
- DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
+ if (ND && isa<TypeDecl>(ND) && !ND->getIdentifier()) {
+ extern QualType getTypeDeclTypeFromASTContext(const TypeDecl *T,
+ ASTContext &Ctx);
+ QualType Ty(
+ getTypeDeclTypeFromASTContext(cast<TypeDecl>(ND), ND->getASTContext()));
+ DB.AddTaggedVal(reinterpret_cast<intptr_t>(Ty.getAsOpaquePtr()),
+ DiagnosticsEngine::ak_qualtype);
+ } else {
+ DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
DiagnosticsEngine::ak_nameddecl);
+ }
return DB;
}
inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
const NamedDecl* ND) {
- PD.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
+ if (ND && isa<TypeDecl>(ND) && !ND->getIdentifier()) {
+ extern QualType getTypeDeclTypeFromASTContext(const TypeDecl *T,
+ ASTContext &Ctx);
+ QualType Ty(
+ getTypeDeclTypeFromASTContext(cast<TypeDecl>(ND), ND->getASTContext()));
+ PD.AddTaggedVal(reinterpret_cast<intptr_t>(Ty.getAsOpaquePtr()),
+ DiagnosticsEngine::ak_qualtype);
+ } else {
+ PD.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
DiagnosticsEngine::ak_nameddecl);
+ }
return PD;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22844.65653.patch
Type: text/x-patch
Size: 3282 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160727/f6056c01/attachment.bin>
More information about the cfe-commits
mailing list