QualType ObjCClassRedefinitionType;
QualType ObjCSelRedefinitionType;
+ /// The identifier 'bool'.
+ mutable IdentifierInfo *BoolName = nullptr;
+
/// The identifier 'NSObject'.
IdentifierInfo *NSObjectName = nullptr;
return NSCopyingName;
}
+ /// Retrieve the identifier 'bool'.
+ IdentifierInfo *getBoolName() const {
+ if (!BoolName)
+ BoolName = &Idents.get("bool");
+ return BoolName;
+ }
+
IdentifierInfo *getMakeIntegerSeqName() const {
if (!MakeIntegerSeqName)
MakeIntegerSeqName = &Idents.get("__make_integer_seq");
/// \brief Describes how types, statements, expressions, and
/// declarations should be printed.
+///
+/// This type is intended to be small and suitable for passing by value.
+/// It is very frequently copied.
struct PrintingPolicy {
- /// \brief Create a default printing policy for C.
+ /// \brief Create a default printing policy for the specified language.
PrintingPolicy(const LangOptions &LO)
- : LangOpts(LO), Indentation(2), SuppressSpecifiers(false),
- SuppressTagKeyword(false),
+ : Indentation(2), SuppressSpecifiers(false),
+ SuppressTagKeyword(LO.CPlusPlus),
IncludeTagDefinition(false), SuppressScope(false),
SuppressUnwrittenScope(false), SuppressInitializers(false),
ConstantArraySizeAsWritten(false), AnonymousTagLocations(true),
SuppressStrongLifetime(false), SuppressLifetimeQualifiers(false),
SuppressTemplateArgsInCXXConstructors(false),
- Bool(LO.Bool), TerseOutput(false), PolishForDeclaration(false),
+ Bool(LO.Bool), Restrict(LO.C99),
+ Alignof(LO.CPlusPlus11), UnderscoreAlignof(LO.C11),
+ UseVoidForZeroParams(!LO.CPlusPlus),
+ TerseOutput(false), PolishForDeclaration(false),
Half(LO.Half), MSWChar(LO.MicrosoftExt && !LO.WChar),
IncludeNewlines(true), MSVCFormatting(false) { }
- /// \brief What language we're printing.
- LangOptions LangOpts;
+ /// \brief Adjust this printing policy for cases where it's known that
+ /// we're printing C++ code (for instance, if AST dumping reaches a
+ /// C++-only construct). This should not be used if a real LangOptions
+ /// object is available.
+ void adjustForCPlusPlus() {
+ SuppressTagKeyword = true;
+ Bool = true;
+ UseVoidForZeroParams = false;
+ }
/// \brief The number of spaces to use to indent each line.
unsigned Indentation : 8;
/// constructors.
unsigned SuppressTemplateArgsInCXXConstructors : 1;
- /// \brief Whether we can use 'bool' rather than '_Bool', even if the language
- /// doesn't actually have 'bool' (because, e.g., it is defined as a macro).
+ /// \brief Whether we can use 'bool' rather than '_Bool' (even if the language
+ /// doesn't actually have 'bool', because, e.g., it is defined as a macro).
unsigned Bool : 1;
+ /// \brief Whether we can use 'restrict' rather than '__restrict'.
+ unsigned Restrict : 1;
+
+ /// \brief Whether we can use 'alignof' rather than '__alignof'.
+ unsigned Alignof : 1;
+
+ /// \brief Whether we can use '_Alignof' rather than '__alignof'.
+ unsigned UnderscoreAlignof : 1;
+
+ /// \brief Whether we should use '(void)' rather than '()' for a function
+ /// prototype with zero parameters.
+ unsigned UseVoidForZeroParams : 1;
+
/// \brief Provide a 'terse' output.
///
/// For example, in this mode we don't print function bodies, class members,
static void printCXXConstructorDestructorName(QualType ClassType,
raw_ostream &OS,
- const PrintingPolicy &Policy) {
+ PrintingPolicy Policy) {
+ // We know we're printing C++ here. Ensure we print types properly.
+ Policy.adjustForCPlusPlus();
+
if (const RecordType *ClassRec = ClassType->getAs<RecordType>()) {
OS << *ClassRec->getDecl();
return;
return;
}
}
- if (!Policy.LangOpts.CPlusPlus) {
- // Passed policy is the default one from operator <<, use a C++ policy.
- LangOptions LO;
- LO.CPlusPlus = true;
- ClassType.print(OS, PrintingPolicy(LO));
- } else {
- ClassType.print(OS, Policy);
- }
+ ClassType.print(OS, Policy);
}
void DeclarationName::print(raw_ostream &OS, const PrintingPolicy &Policy) {
OS << *Rec->getDecl();
return;
}
- if (!Policy.LangOpts.CPlusPlus) {
- // Passed policy is the default one from operator <<, use a C++ policy.
- LangOptions LO;
- LO.CPlusPlus = true;
- LO.Bool = true;
- Type.print(OS, PrintingPolicy(LO));
- } else {
- Type.print(OS, Policy);
- }
+ // We know we're printing C++ here, ensure we print 'bool' properly.
+ PrintingPolicy CXXPolicy = Policy;
+ CXXPolicy.adjustForCPlusPlus();
+ Type.print(OS, CXXPolicy);
return;
}
case DeclarationName::CXXUsingDirective:
OS << "sizeof";
break;
case UETT_AlignOf:
- if (Policy.LangOpts.CPlusPlus)
+ if (Policy.Alignof)
OS << "alignof";
- else if (Policy.LangOpts.C11)
+ else if (Policy.UnderscoreAlignof)
OS << "_Alignof";
else
OS << "__alignof";
}
void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) {
- if (Policy.LangOpts.CPlusPlus) {
+ if (Node->getType()->getAsCXXRecordDecl()) {
OS << "/*implicit*/";
Node->getType().print(OS, Policy);
OS << "()";
};
}
-static void AppendTypeQualList(raw_ostream &OS, unsigned TypeQuals, bool C99) {
+static void AppendTypeQualList(raw_ostream &OS, unsigned TypeQuals,
+ bool HasRestrictKeyword) {
bool appendSpace = false;
if (TypeQuals & Qualifiers::Const) {
OS << "const";
}
if (TypeQuals & Qualifiers::Restrict) {
if (appendSpace) OS << ' ';
- if (C99) {
+ if (HasRestrictKeyword) {
OS << "restrict";
} else {
OS << "__restrict";
raw_ostream &OS) {
OS << '[';
if (T->getIndexTypeQualifiers().hasQualifiers()) {
- AppendTypeQualList(OS, T->getIndexTypeCVRQualifiers(), Policy.LangOpts.C99);
+ AppendTypeQualList(OS, T->getIndexTypeCVRQualifiers(),
+ Policy.Restrict);
OS << ' ';
}
raw_ostream &OS) {
OS << '[';
if (T->getIndexTypeQualifiers().hasQualifiers()) {
- AppendTypeQualList(OS, T->getIndexTypeCVRQualifiers(), Policy.LangOpts.C99);
+ AppendTypeQualList(OS, T->getIndexTypeCVRQualifiers(), Policy.Restrict);
OS << ' ';
}
if (T->getNumParams())
OS << ", ";
OS << "...";
- } else if (T->getNumParams() == 0 && !Policy.LangOpts.CPlusPlus) {
+ } else if (T->getNumParams() == 0 && Policy.UseVoidForZeroParams) {
// Do not emit int() if we have a proto, emit 'int(void)'.
OS << "void";
}
if (unsigned quals = T->getTypeQuals()) {
OS << ' ';
- AppendTypeQualList(OS, quals, Policy.LangOpts.C99);
+ AppendTypeQualList(OS, quals, Policy.Restrict);
}
switch (T->getRefQualifier()) {
bool HasKindDecoration = false;
- // bool SuppressTagKeyword
- // = Policy.LangOpts.CPlusPlus || Policy.SuppressTagKeyword;
-
// We don't print tags unless this is an elaborated type.
// In C, we just assume every RecordType is an elaborated type.
- if (!(Policy.LangOpts.CPlusPlus || Policy.SuppressTagKeyword ||
- D->getTypedefNameForAnonDecl())) {
+ if (!Policy.SuppressTagKeyword && !D->getTypedefNameForAnonDecl()) {
HasKindDecoration = true;
OS << D->getKindName();
OS << ' ';
unsigned quals = getCVRQualifiers();
if (quals) {
- AppendTypeQualList(OS, quals, Policy.LangOpts.C99);
+ AppendTypeQualList(OS, quals, Policy.Restrict);
addSpace = true;
}
if (hasUnaligned()) {
bool AttrsLastTime = false;
ParsedAttributesWithRange attrs(AttrFactory);
// We use Sema's policy to get bool macros right.
- const PrintingPolicy &Policy = Actions.getPrintingPolicy();
+ PrintingPolicy Policy = Actions.getPrintingPolicy();
while (1) {
bool isInvalid = false;
bool isStorageClass = false;
PrintingPolicy Sema::getPrintingPolicy(const ASTContext &Context,
const Preprocessor &PP) {
PrintingPolicy Policy = Context.getPrintingPolicy();
+ // Our printing policy is copied over the ASTContext printing policy whenever
+ // a diagnostic is emitted, so recompute it.
Policy.Bool = Context.getLangOpts().Bool;
if (!Policy.Bool) {
- if (const MacroInfo *
- BoolMacro = PP.getMacroInfo(&Context.Idents.get("bool"))) {
+ if (const MacroInfo *BoolMacro = PP.getMacroInfo(Context.getBoolName())) {
Policy.Bool = BoolMacro->isObjectLike() &&
- BoolMacro->getNumTokens() == 1 &&
- BoolMacro->getReplacementToken(0).is(tok::kw__Bool);
+ BoolMacro->getNumTokens() == 1 &&
+ BoolMacro->getReplacementToken(0).is(tok::kw__Bool);
}
}
ResultBuilder &Results) {
CodeCompletionAllocator &Allocator = Results.getAllocator();
CodeCompletionBuilder Builder(Allocator, Results.getCodeCompletionTUInfo());
- PrintingPolicy Policy = getCompletionPrintingPolicy(SemaRef);
typedef CodeCompletionResult Result;
switch (CCC) {
// CHECK: 6: B([B1.5]) (Base initializer)
// CHECK: 7: (CXXConstructExpr, class A)
// CHECK: 8: A([B1.7]) (Base initializer)
-// CHECK: 9: /*implicit*/int()
+// CHECK: 9: /*implicit*/(int)0
// CHECK: 10: i([B1.9]) (Member initializer)
// CHECK: 11: this
// CHECK: 12: [B1.11]->i
// CHECK: 14: a([B1.13]) (Member initializer)
// CHECK: 15: ~B() (Temporary object destructor)
// CHECK: 16: ~A() (Temporary object destructor)
-// CHECK: 17: /*implicit*/int()
+// CHECK: 17: /*implicit*/(int)0
// CHECK: 18: b([B1.17]) (Member initializer)
// CHECK: Preds (1): B2
// CHECK: Succs (1): B0
.**(int A::**) 0; // expected-warning {{indirection of non-volatile null pointer will be deleted}} expected-note {{consider}}
}
}
+
+namespace PR27558 {
+ template<typename Args> struct A { void f(); };
+ template<typename Args> struct B : A<Args> {
+ using A<Args>::f;
+ B() { (void)&B<Args>::f; }
+ };
+ B<int> b;
+}