1 //===--- DeclSpec.cpp - Declaration Specifier Semantic Analysis -----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements semantic analysis for declaration specifiers.
12 //===----------------------------------------------------------------------===//
14 #include "clang/Sema/DeclSpec.h"
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/DeclCXX.h"
17 #include "clang/AST/Expr.h"
18 #include "clang/AST/LocInfoType.h"
19 #include "clang/AST/TypeLoc.h"
20 #include "clang/Basic/LangOptions.h"
21 #include "clang/Basic/TargetInfo.h"
22 #include "clang/Sema/ParsedTemplate.h"
23 #include "clang/Sema/Sema.h"
24 #include "clang/Sema/SemaDiagnostic.h"
25 #include "llvm/ADT/STLExtras.h"
26 #include "llvm/ADT/SmallString.h"
28 using namespace clang;
31 void UnqualifiedId::setTemplateId(TemplateIdAnnotation *TemplateId) {
32 assert(TemplateId && "NULL template-id annotation?");
33 Kind = UnqualifiedIdKind::IK_TemplateId;
34 this->TemplateId = TemplateId;
35 StartLocation = TemplateId->TemplateNameLoc;
36 EndLocation = TemplateId->RAngleLoc;
39 void UnqualifiedId::setConstructorTemplateId(TemplateIdAnnotation *TemplateId) {
40 assert(TemplateId && "NULL template-id annotation?");
41 Kind = UnqualifiedIdKind::IK_ConstructorTemplateId;
42 this->TemplateId = TemplateId;
43 StartLocation = TemplateId->TemplateNameLoc;
44 EndLocation = TemplateId->RAngleLoc;
47 void CXXScopeSpec::Extend(ASTContext &Context, SourceLocation TemplateKWLoc,
48 TypeLoc TL, SourceLocation ColonColonLoc) {
49 Builder.Extend(Context, TemplateKWLoc, TL, ColonColonLoc);
50 if (Range.getBegin().isInvalid())
51 Range.setBegin(TL.getBeginLoc());
52 Range.setEnd(ColonColonLoc);
54 assert(Range == Builder.getSourceRange() &&
55 "NestedNameSpecifierLoc range computation incorrect");
58 void CXXScopeSpec::Extend(ASTContext &Context, IdentifierInfo *Identifier,
59 SourceLocation IdentifierLoc,
60 SourceLocation ColonColonLoc) {
61 Builder.Extend(Context, Identifier, IdentifierLoc, ColonColonLoc);
63 if (Range.getBegin().isInvalid())
64 Range.setBegin(IdentifierLoc);
65 Range.setEnd(ColonColonLoc);
67 assert(Range == Builder.getSourceRange() &&
68 "NestedNameSpecifierLoc range computation incorrect");
71 void CXXScopeSpec::Extend(ASTContext &Context, NamespaceDecl *Namespace,
72 SourceLocation NamespaceLoc,
73 SourceLocation ColonColonLoc) {
74 Builder.Extend(Context, Namespace, NamespaceLoc, ColonColonLoc);
76 if (Range.getBegin().isInvalid())
77 Range.setBegin(NamespaceLoc);
78 Range.setEnd(ColonColonLoc);
80 assert(Range == Builder.getSourceRange() &&
81 "NestedNameSpecifierLoc range computation incorrect");
84 void CXXScopeSpec::Extend(ASTContext &Context, NamespaceAliasDecl *Alias,
85 SourceLocation AliasLoc,
86 SourceLocation ColonColonLoc) {
87 Builder.Extend(Context, Alias, AliasLoc, ColonColonLoc);
89 if (Range.getBegin().isInvalid())
90 Range.setBegin(AliasLoc);
91 Range.setEnd(ColonColonLoc);
93 assert(Range == Builder.getSourceRange() &&
94 "NestedNameSpecifierLoc range computation incorrect");
97 void CXXScopeSpec::MakeGlobal(ASTContext &Context,
98 SourceLocation ColonColonLoc) {
99 Builder.MakeGlobal(Context, ColonColonLoc);
101 Range = SourceRange(ColonColonLoc);
103 assert(Range == Builder.getSourceRange() &&
104 "NestedNameSpecifierLoc range computation incorrect");
107 void CXXScopeSpec::MakeSuper(ASTContext &Context, CXXRecordDecl *RD,
108 SourceLocation SuperLoc,
109 SourceLocation ColonColonLoc) {
110 Builder.MakeSuper(Context, RD, SuperLoc, ColonColonLoc);
112 Range.setBegin(SuperLoc);
113 Range.setEnd(ColonColonLoc);
115 assert(Range == Builder.getSourceRange() &&
116 "NestedNameSpecifierLoc range computation incorrect");
119 void CXXScopeSpec::MakeTrivial(ASTContext &Context,
120 NestedNameSpecifier *Qualifier, SourceRange R) {
121 Builder.MakeTrivial(Context, Qualifier, R);
125 void CXXScopeSpec::Adopt(NestedNameSpecifierLoc Other) {
127 Range = SourceRange();
132 Range = Other.getSourceRange();
133 Builder.Adopt(Other);
136 SourceLocation CXXScopeSpec::getLastQualifierNameLoc() const {
137 if (!Builder.getRepresentation())
138 return SourceLocation();
139 return Builder.getTemporary().getLocalBeginLoc();
142 NestedNameSpecifierLoc
143 CXXScopeSpec::getWithLocInContext(ASTContext &Context) const {
144 if (!Builder.getRepresentation())
145 return NestedNameSpecifierLoc();
147 return Builder.getWithLocInContext(Context);
150 /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
151 /// "TheDeclarator" is the declarator that this will be added to.
152 DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto,
154 SourceLocation LParenLoc,
157 SourceLocation EllipsisLoc,
158 SourceLocation RParenLoc,
160 bool RefQualifierIsLvalueRef,
161 SourceLocation RefQualifierLoc,
162 SourceLocation ConstQualifierLoc,
164 VolatileQualifierLoc,
166 RestrictQualifierLoc,
167 SourceLocation MutableLoc,
168 ExceptionSpecificationType
170 SourceRange ESpecRange,
171 ParsedType *Exceptions,
172 SourceRange *ExceptionRanges,
173 unsigned NumExceptions,
175 CachedTokens *ExceptionSpecTokens,
178 SourceLocation LocalRangeBegin,
179 SourceLocation LocalRangeEnd,
180 Declarator &TheDeclarator,
181 TypeResult TrailingReturnType) {
182 assert(!(TypeQuals & DeclSpec::TQ_atomic) &&
183 "function cannot have _Atomic qualifier");
187 I.Loc = LocalRangeBegin;
188 I.EndLoc = LocalRangeEnd;
189 I.Fun.hasPrototype = hasProto;
190 I.Fun.isVariadic = EllipsisLoc.isValid();
191 I.Fun.isAmbiguous = isAmbiguous;
192 I.Fun.LParenLoc = LParenLoc.getRawEncoding();
193 I.Fun.EllipsisLoc = EllipsisLoc.getRawEncoding();
194 I.Fun.RParenLoc = RParenLoc.getRawEncoding();
195 I.Fun.DeleteParams = false;
196 I.Fun.TypeQuals = TypeQuals;
197 I.Fun.NumParams = NumParams;
198 I.Fun.Params = nullptr;
199 I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef;
200 I.Fun.RefQualifierLoc = RefQualifierLoc.getRawEncoding();
201 I.Fun.ConstQualifierLoc = ConstQualifierLoc.getRawEncoding();
202 I.Fun.VolatileQualifierLoc = VolatileQualifierLoc.getRawEncoding();
203 I.Fun.RestrictQualifierLoc = RestrictQualifierLoc.getRawEncoding();
204 I.Fun.MutableLoc = MutableLoc.getRawEncoding();
205 I.Fun.ExceptionSpecType = ESpecType;
206 I.Fun.ExceptionSpecLocBeg = ESpecRange.getBegin().getRawEncoding();
207 I.Fun.ExceptionSpecLocEnd = ESpecRange.getEnd().getRawEncoding();
208 I.Fun.NumExceptionsOrDecls = 0;
209 I.Fun.Exceptions = nullptr;
210 I.Fun.NoexceptExpr = nullptr;
211 I.Fun.HasTrailingReturnType = TrailingReturnType.isUsable() ||
212 TrailingReturnType.isInvalid();
213 I.Fun.TrailingReturnType = TrailingReturnType.get();
215 assert(I.Fun.TypeQuals == TypeQuals && "bitfield overflow");
216 assert(I.Fun.ExceptionSpecType == ESpecType && "bitfield overflow");
218 // new[] a parameter array if needed.
220 // If the 'InlineParams' in Declarator is unused and big enough, put our
221 // parameter list there (in an effort to avoid new/delete traffic). If it
222 // is already used (consider a function returning a function pointer) or too
223 // small (function with too many parameters), go to the heap.
224 if (!TheDeclarator.InlineStorageUsed &&
225 NumParams <= llvm::array_lengthof(TheDeclarator.InlineParams)) {
226 I.Fun.Params = TheDeclarator.InlineParams;
227 new (I.Fun.Params) ParamInfo[NumParams];
228 I.Fun.DeleteParams = false;
229 TheDeclarator.InlineStorageUsed = true;
231 I.Fun.Params = new DeclaratorChunk::ParamInfo[NumParams];
232 I.Fun.DeleteParams = true;
234 for (unsigned i = 0; i < NumParams; i++)
235 I.Fun.Params[i] = std::move(Params[i]);
238 // Check what exception specification information we should actually store.
240 default: break; // By default, save nothing.
242 // new[] an exception array if needed
244 I.Fun.NumExceptionsOrDecls = NumExceptions;
245 I.Fun.Exceptions = new DeclaratorChunk::TypeAndRange[NumExceptions];
246 for (unsigned i = 0; i != NumExceptions; ++i) {
247 I.Fun.Exceptions[i].Ty = Exceptions[i];
248 I.Fun.Exceptions[i].Range = ExceptionRanges[i];
253 case EST_DependentNoexcept:
254 case EST_NoexceptFalse:
255 case EST_NoexceptTrue:
256 I.Fun.NoexceptExpr = NoexceptExpr;
260 I.Fun.ExceptionSpecTokens = ExceptionSpecTokens;
264 if (!DeclsInPrototype.empty()) {
265 assert(ESpecType == EST_None && NumExceptions == 0 &&
266 "cannot have exception specifiers and decls in prototype");
267 I.Fun.NumExceptionsOrDecls = DeclsInPrototype.size();
268 // Copy the array of decls into stable heap storage.
269 I.Fun.DeclsInPrototype = new NamedDecl *[DeclsInPrototype.size()];
270 for (size_t J = 0; J < DeclsInPrototype.size(); ++J)
271 I.Fun.DeclsInPrototype[J] = DeclsInPrototype[J];
277 void Declarator::setDecompositionBindings(
278 SourceLocation LSquareLoc,
279 ArrayRef<DecompositionDeclarator::Binding> Bindings,
280 SourceLocation RSquareLoc) {
281 assert(!hasName() && "declarator given multiple names!");
283 BindingGroup.LSquareLoc = LSquareLoc;
284 BindingGroup.RSquareLoc = RSquareLoc;
285 BindingGroup.NumBindings = Bindings.size();
286 Range.setEnd(RSquareLoc);
288 // We're now past the identifier.
289 SetIdentifier(nullptr, LSquareLoc);
290 Name.EndLocation = RSquareLoc;
292 // Allocate storage for bindings and stash them away.
293 if (Bindings.size()) {
294 if (!InlineStorageUsed &&
295 Bindings.size() <= llvm::array_lengthof(InlineBindings)) {
296 BindingGroup.Bindings = InlineBindings;
297 BindingGroup.DeleteBindings = false;
298 InlineStorageUsed = true;
300 BindingGroup.Bindings =
301 new DecompositionDeclarator::Binding[Bindings.size()];
302 BindingGroup.DeleteBindings = true;
304 std::uninitialized_copy(Bindings.begin(), Bindings.end(),
305 BindingGroup.Bindings);
309 bool Declarator::isDeclarationOfFunction() const {
310 for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
311 switch (DeclTypeInfo[i].Kind) {
312 case DeclaratorChunk::Function:
314 case DeclaratorChunk::Paren:
316 case DeclaratorChunk::Pointer:
317 case DeclaratorChunk::Reference:
318 case DeclaratorChunk::Array:
319 case DeclaratorChunk::BlockPointer:
320 case DeclaratorChunk::MemberPointer:
321 case DeclaratorChunk::Pipe:
324 llvm_unreachable("Invalid type chunk");
327 switch (DS.getTypeSpecType()) {
354 case TST_unknown_anytype:
355 case TST_unspecified:
358 #define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
359 #include "clang/Basic/OpenCLImageTypes.def"
362 case TST_decltype_auto:
363 // This must have an initializer, so can't be a function declaration,
364 // even if the initializer has function type.
369 if (Expr *E = DS.getRepAsExpr())
370 return E->getType()->isFunctionType();
373 case TST_underlyingType:
375 case TST_typeofType: {
376 QualType QT = DS.getRepAsType().get();
380 if (const LocInfoType *LIT = dyn_cast<LocInfoType>(QT))
386 return QT->isFunctionType();
390 llvm_unreachable("Invalid TypeSpecType!");
393 bool Declarator::isStaticMember() {
394 assert(getContext() == DeclaratorContext::MemberContext);
395 return getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
396 (getName().Kind == UnqualifiedIdKind::IK_OperatorFunctionId &&
397 CXXMethodDecl::isStaticOverloadedOperator(
398 getName().OperatorFunctionId.Operator));
401 bool Declarator::isCtorOrDtor() {
402 return (getName().getKind() == UnqualifiedIdKind::IK_ConstructorName) ||
403 (getName().getKind() == UnqualifiedIdKind::IK_DestructorName);
406 bool DeclSpec::hasTagDefinition() const {
409 return cast<TagDecl>(getRepAsDecl())->isCompleteDefinition();
412 /// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
413 /// declaration specifier includes.
415 unsigned DeclSpec::getParsedSpecifiers() const {
417 if (StorageClassSpec != SCS_unspecified ||
418 ThreadStorageClassSpec != TSCS_unspecified)
419 Res |= PQ_StorageClassSpecifier;
421 if (TypeQualifiers != TQ_unspecified)
422 Res |= PQ_TypeQualifier;
424 if (hasTypeSpecifier())
425 Res |= PQ_TypeSpecifier;
427 if (FS_inline_specified || FS_virtual_specified || FS_explicit_specified ||
428 FS_noreturn_specified || FS_forceinline_specified)
429 Res |= PQ_FunctionSpecifier;
433 template <class T> static bool BadSpecifier(T TNew, T TPrev,
434 const char *&PrevSpec,
436 bool IsExtension = true) {
437 PrevSpec = DeclSpec::getSpecifierName(TPrev);
439 DiagID = diag::err_invalid_decl_spec_combination;
441 DiagID = IsExtension ? diag::ext_duplicate_declspec :
442 diag::warn_duplicate_declspec;
446 const char *DeclSpec::getSpecifierName(DeclSpec::SCS S) {
448 case DeclSpec::SCS_unspecified: return "unspecified";
449 case DeclSpec::SCS_typedef: return "typedef";
450 case DeclSpec::SCS_extern: return "extern";
451 case DeclSpec::SCS_static: return "static";
452 case DeclSpec::SCS_auto: return "auto";
453 case DeclSpec::SCS_register: return "register";
454 case DeclSpec::SCS_private_extern: return "__private_extern__";
455 case DeclSpec::SCS_mutable: return "mutable";
457 llvm_unreachable("Unknown typespec!");
460 const char *DeclSpec::getSpecifierName(DeclSpec::TSCS S) {
462 case DeclSpec::TSCS_unspecified: return "unspecified";
463 case DeclSpec::TSCS___thread: return "__thread";
464 case DeclSpec::TSCS_thread_local: return "thread_local";
465 case DeclSpec::TSCS__Thread_local: return "_Thread_local";
467 llvm_unreachable("Unknown typespec!");
470 const char *DeclSpec::getSpecifierName(TSW W) {
472 case TSW_unspecified: return "unspecified";
473 case TSW_short: return "short";
474 case TSW_long: return "long";
475 case TSW_longlong: return "long long";
477 llvm_unreachable("Unknown typespec!");
480 const char *DeclSpec::getSpecifierName(TSC C) {
482 case TSC_unspecified: return "unspecified";
483 case TSC_imaginary: return "imaginary";
484 case TSC_complex: return "complex";
486 llvm_unreachable("Unknown typespec!");
490 const char *DeclSpec::getSpecifierName(TSS S) {
492 case TSS_unspecified: return "unspecified";
493 case TSS_signed: return "signed";
494 case TSS_unsigned: return "unsigned";
496 llvm_unreachable("Unknown typespec!");
499 const char *DeclSpec::getSpecifierName(DeclSpec::TST T,
500 const PrintingPolicy &Policy) {
502 case DeclSpec::TST_unspecified: return "unspecified";
503 case DeclSpec::TST_void: return "void";
504 case DeclSpec::TST_char: return "char";
505 case DeclSpec::TST_wchar: return Policy.MSWChar ? "__wchar_t" : "wchar_t";
506 case DeclSpec::TST_char8: return "char8_t";
507 case DeclSpec::TST_char16: return "char16_t";
508 case DeclSpec::TST_char32: return "char32_t";
509 case DeclSpec::TST_int: return "int";
510 case DeclSpec::TST_int128: return "__int128";
511 case DeclSpec::TST_half: return "half";
512 case DeclSpec::TST_float: return "float";
513 case DeclSpec::TST_double: return "double";
514 case DeclSpec::TST_accum: return "_Accum";
515 case DeclSpec::TST_fract: return "_Fract";
516 case DeclSpec::TST_float16: return "_Float16";
517 case DeclSpec::TST_float128: return "__float128";
518 case DeclSpec::TST_bool: return Policy.Bool ? "bool" : "_Bool";
519 case DeclSpec::TST_decimal32: return "_Decimal32";
520 case DeclSpec::TST_decimal64: return "_Decimal64";
521 case DeclSpec::TST_decimal128: return "_Decimal128";
522 case DeclSpec::TST_enum: return "enum";
523 case DeclSpec::TST_class: return "class";
524 case DeclSpec::TST_union: return "union";
525 case DeclSpec::TST_struct: return "struct";
526 case DeclSpec::TST_interface: return "__interface";
527 case DeclSpec::TST_typename: return "type-name";
528 case DeclSpec::TST_typeofType:
529 case DeclSpec::TST_typeofExpr: return "typeof";
530 case DeclSpec::TST_auto: return "auto";
531 case DeclSpec::TST_auto_type: return "__auto_type";
532 case DeclSpec::TST_decltype: return "(decltype)";
533 case DeclSpec::TST_decltype_auto: return "decltype(auto)";
534 case DeclSpec::TST_underlyingType: return "__underlying_type";
535 case DeclSpec::TST_unknown_anytype: return "__unknown_anytype";
536 case DeclSpec::TST_atomic: return "_Atomic";
537 #define GENERIC_IMAGE_TYPE(ImgType, Id) \
538 case DeclSpec::TST_##ImgType##_t: \
539 return #ImgType "_t";
540 #include "clang/Basic/OpenCLImageTypes.def"
541 case DeclSpec::TST_error: return "(error)";
543 llvm_unreachable("Unknown typespec!");
546 const char *DeclSpec::getSpecifierName(TQ T) {
548 case DeclSpec::TQ_unspecified: return "unspecified";
549 case DeclSpec::TQ_const: return "const";
550 case DeclSpec::TQ_restrict: return "restrict";
551 case DeclSpec::TQ_volatile: return "volatile";
552 case DeclSpec::TQ_atomic: return "_Atomic";
553 case DeclSpec::TQ_unaligned: return "__unaligned";
555 llvm_unreachable("Unknown typespec!");
558 bool DeclSpec::SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc,
559 const char *&PrevSpec,
561 const PrintingPolicy &Policy) {
562 // OpenCL v1.1 s6.8g: "The extern, static, auto and register storage-class
563 // specifiers are not supported.
564 // It seems sensible to prohibit private_extern too
565 // The cl_clang_storage_class_specifiers extension enables support for
566 // these storage-class specifiers.
567 // OpenCL v1.2 s6.8 changes this to "The auto and register storage-class
568 // specifiers are not supported."
569 if (S.getLangOpts().OpenCL &&
570 !S.getOpenCLOptions().isEnabled("cl_clang_storage_class_specifiers")) {
573 case SCS_private_extern:
575 if (S.getLangOpts().OpenCLVersion < 120) {
576 DiagID = diag::err_opencl_unknown_type_specifier;
577 PrevSpec = getSpecifierName(SC);
583 DiagID = diag::err_opencl_unknown_type_specifier;
584 PrevSpec = getSpecifierName(SC);
591 if (StorageClassSpec != SCS_unspecified) {
592 // Maybe this is an attempt to use C++11 'auto' outside of C++11 mode.
593 bool isInvalid = true;
594 if (TypeSpecType == TST_unspecified && S.getLangOpts().CPlusPlus) {
596 return SetTypeSpecType(TST_auto, Loc, PrevSpec, DiagID, Policy);
597 if (StorageClassSpec == SCS_auto) {
598 isInvalid = SetTypeSpecType(TST_auto, StorageClassSpecLoc,
599 PrevSpec, DiagID, Policy);
600 assert(!isInvalid && "auto SCS -> TST recovery failed");
604 // Changing storage class is allowed only if the previous one
605 // was the 'extern' that is part of a linkage specification and
606 // the new storage class is 'typedef'.
608 !(SCS_extern_in_linkage_spec &&
609 StorageClassSpec == SCS_extern &&
611 return BadSpecifier(SC, (SCS)StorageClassSpec, PrevSpec, DiagID);
613 StorageClassSpec = SC;
614 StorageClassSpecLoc = Loc;
615 assert((unsigned)SC == StorageClassSpec && "SCS constants overflow bitfield");
619 bool DeclSpec::SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc,
620 const char *&PrevSpec,
622 if (ThreadStorageClassSpec != TSCS_unspecified)
623 return BadSpecifier(TSC, (TSCS)ThreadStorageClassSpec, PrevSpec, DiagID);
625 ThreadStorageClassSpec = TSC;
626 ThreadStorageClassSpecLoc = Loc;
630 /// These methods set the specified attribute of the DeclSpec, but return true
631 /// and ignore the request if invalid (e.g. "extern" then "auto" is
633 bool DeclSpec::SetTypeSpecWidth(TSW W, SourceLocation Loc,
634 const char *&PrevSpec,
636 const PrintingPolicy &Policy) {
637 // Overwrite TSWRange.Begin only if TypeSpecWidth was unspecified, so that
638 // for 'long long' we will keep the source location of the first 'long'.
639 if (TypeSpecWidth == TSW_unspecified)
640 TSWRange.setBegin(Loc);
641 // Allow turning long -> long long.
642 else if (W != TSW_longlong || TypeSpecWidth != TSW_long)
643 return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID);
645 // Remember location of the last 'long'
646 TSWRange.setEnd(Loc);
650 bool DeclSpec::SetTypeSpecComplex(TSC C, SourceLocation Loc,
651 const char *&PrevSpec,
653 if (TypeSpecComplex != TSC_unspecified)
654 return BadSpecifier(C, (TSC)TypeSpecComplex, PrevSpec, DiagID);
660 bool DeclSpec::SetTypeSpecSign(TSS S, SourceLocation Loc,
661 const char *&PrevSpec,
663 if (TypeSpecSign != TSS_unspecified)
664 return BadSpecifier(S, (TSS)TypeSpecSign, PrevSpec, DiagID);
670 bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
671 const char *&PrevSpec,
674 const PrintingPolicy &Policy) {
675 return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Policy);
678 bool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc,
679 SourceLocation TagNameLoc,
680 const char *&PrevSpec,
683 const PrintingPolicy &Policy) {
684 assert(isTypeRep(T) && "T does not store a type");
685 assert(Rep && "no type provided!");
686 if (TypeSpecType != TST_unspecified) {
687 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
688 DiagID = diag::err_invalid_decl_spec_combination;
694 TSTNameLoc = TagNameLoc;
695 TypeSpecOwned = false;
699 bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
700 const char *&PrevSpec,
703 const PrintingPolicy &Policy) {
704 assert(isExprRep(T) && "T does not store an expr");
705 assert(Rep && "no expression provided!");
706 if (TypeSpecType != TST_unspecified) {
707 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
708 DiagID = diag::err_invalid_decl_spec_combination;
715 TypeSpecOwned = false;
719 bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
720 const char *&PrevSpec,
722 Decl *Rep, bool Owned,
723 const PrintingPolicy &Policy) {
724 return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Owned, Policy);
727 bool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc,
728 SourceLocation TagNameLoc,
729 const char *&PrevSpec,
731 Decl *Rep, bool Owned,
732 const PrintingPolicy &Policy) {
733 assert(isDeclRep(T) && "T does not store a decl");
734 // Unlike the other cases, we don't assert that we actually get a decl.
736 if (TypeSpecType != TST_unspecified) {
737 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
738 DiagID = diag::err_invalid_decl_spec_combination;
744 TSTNameLoc = TagNameLoc;
745 TypeSpecOwned = Owned && Rep != nullptr;
749 bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc,
750 const char *&PrevSpec,
752 const PrintingPolicy &Policy) {
753 assert(!isDeclRep(T) && !isTypeRep(T) && !isExprRep(T) &&
754 "rep required for these type-spec kinds!");
755 if (TypeSpecType != TST_unspecified) {
756 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
757 DiagID = diag::err_invalid_decl_spec_combination;
762 if (TypeAltiVecVector && (T == TST_bool) && !TypeAltiVecBool) {
763 TypeAltiVecBool = true;
767 TypeSpecOwned = false;
771 bool DeclSpec::SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec,
775 DiagID = diag::warn_duplicate_declspec;
784 bool DeclSpec::SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc,
785 const char *&PrevSpec, unsigned &DiagID,
786 const PrintingPolicy &Policy) {
787 if (TypeSpecType != TST_unspecified) {
788 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
789 DiagID = diag::err_invalid_vector_decl_spec_combination;
792 TypeAltiVecVector = isAltiVecVector;
797 bool DeclSpec::SetTypePipe(bool isPipe, SourceLocation Loc,
798 const char *&PrevSpec, unsigned &DiagID,
799 const PrintingPolicy &Policy) {
801 if (TypeSpecType != TST_unspecified) {
802 PrevSpec = DeclSpec::getSpecifierName((TST)TypeSpecType, Policy);
803 DiagID = diag::err_invalid_decl_spec_combination;
808 TypeSpecPipe = TSP_pipe;
813 bool DeclSpec::SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc,
814 const char *&PrevSpec, unsigned &DiagID,
815 const PrintingPolicy &Policy) {
816 if (!TypeAltiVecVector || TypeAltiVecPixel ||
817 (TypeSpecType != TST_unspecified)) {
818 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
819 DiagID = diag::err_invalid_pixel_decl_spec_combination;
822 TypeAltiVecPixel = isAltiVecPixel;
828 bool DeclSpec::SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc,
829 const char *&PrevSpec, unsigned &DiagID,
830 const PrintingPolicy &Policy) {
831 if (!TypeAltiVecVector || TypeAltiVecBool ||
832 (TypeSpecType != TST_unspecified)) {
833 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType, Policy);
834 DiagID = diag::err_invalid_vector_bool_decl_spec;
837 TypeAltiVecBool = isAltiVecBool;
843 bool DeclSpec::SetTypeSpecError() {
844 TypeSpecType = TST_error;
845 TypeSpecOwned = false;
846 TSTLoc = SourceLocation();
847 TSTNameLoc = SourceLocation();
851 bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
852 unsigned &DiagID, const LangOptions &Lang) {
853 // Duplicates are permitted in C99 onwards, but are not permitted in C89 or
854 // C++. However, since this is likely not what the user intended, we will
855 // always warn. We do not need to set the qualifier's location since we
857 if (TypeQualifiers & T) {
858 bool IsExtension = true;
861 return BadSpecifier(T, T, PrevSpec, DiagID, IsExtension);
866 case TQ_unspecified: break;
867 case TQ_const: TQ_constLoc = Loc; return false;
868 case TQ_restrict: TQ_restrictLoc = Loc; return false;
869 case TQ_volatile: TQ_volatileLoc = Loc; return false;
870 case TQ_unaligned: TQ_unalignedLoc = Loc; return false;
871 case TQ_atomic: TQ_atomicLoc = Loc; return false;
874 llvm_unreachable("Unknown type qualifier!");
877 bool DeclSpec::setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
879 // 'inline inline' is ok. However, since this is likely not what the user
880 // intended, we will always warn, similar to duplicates of type qualifiers.
881 if (FS_inline_specified) {
882 DiagID = diag::warn_duplicate_declspec;
886 FS_inline_specified = true;
891 bool DeclSpec::setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec,
893 if (FS_forceinline_specified) {
894 DiagID = diag::warn_duplicate_declspec;
895 PrevSpec = "__forceinline";
898 FS_forceinline_specified = true;
899 FS_forceinlineLoc = Loc;
903 bool DeclSpec::setFunctionSpecVirtual(SourceLocation Loc,
904 const char *&PrevSpec,
906 // 'virtual virtual' is ok, but warn as this is likely not what the user
908 if (FS_virtual_specified) {
909 DiagID = diag::warn_duplicate_declspec;
910 PrevSpec = "virtual";
913 FS_virtual_specified = true;
918 bool DeclSpec::setFunctionSpecExplicit(SourceLocation Loc,
919 const char *&PrevSpec,
921 // 'explicit explicit' is ok, but warn as this is likely not what the user
923 if (FS_explicit_specified) {
924 DiagID = diag::warn_duplicate_declspec;
925 PrevSpec = "explicit";
928 FS_explicit_specified = true;
929 FS_explicitLoc = Loc;
933 bool DeclSpec::setFunctionSpecNoreturn(SourceLocation Loc,
934 const char *&PrevSpec,
936 // '_Noreturn _Noreturn' is ok, but warn as this is likely not what the user
938 if (FS_noreturn_specified) {
939 DiagID = diag::warn_duplicate_declspec;
940 PrevSpec = "_Noreturn";
943 FS_noreturn_specified = true;
944 FS_noreturnLoc = Loc;
948 bool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
950 if (Friend_specified) {
952 // Keep the later location, so that we can later diagnose ill-formed
953 // declarations like 'friend class X friend;'. Per [class.friend]p3,
954 // 'friend' must be the first token in a friend declaration that is
955 // not a function declaration.
957 DiagID = diag::warn_duplicate_declspec;
961 Friend_specified = true;
966 bool DeclSpec::setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec,
968 if (isModulePrivateSpecified()) {
969 PrevSpec = "__module_private__";
970 DiagID = diag::ext_duplicate_declspec;
974 ModulePrivateLoc = Loc;
978 bool DeclSpec::SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec,
980 // 'constexpr constexpr' is ok, but warn as this is likely not what the user
982 if (Constexpr_specified) {
983 DiagID = diag::warn_duplicate_declspec;
984 PrevSpec = "constexpr";
987 Constexpr_specified = true;
992 void DeclSpec::SaveWrittenBuiltinSpecs() {
993 writtenBS.Sign = getTypeSpecSign();
994 writtenBS.Width = getTypeSpecWidth();
995 writtenBS.Type = getTypeSpecType();
996 // Search the list of attributes for the presence of a mode attribute.
997 writtenBS.ModeAttr = getAttributes().hasAttribute(ParsedAttr::AT_Mode);
1000 /// Finish - This does final analysis of the declspec, rejecting things like
1001 /// "_Imaginary" (lacking an FP type). This returns a diagnostic to issue or
1002 /// diag::NUM_DIAGNOSTICS if there is no error. After calling this method,
1003 /// DeclSpec is guaranteed self-consistent, even if an error occurred.
1004 void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
1005 // Before possibly changing their values, save specs as written.
1006 SaveWrittenBuiltinSpecs();
1008 // Check the type specifier components first.
1010 // If decltype(auto) is used, no other type specifiers are permitted.
1011 if (TypeSpecType == TST_decltype_auto &&
1012 (TypeSpecWidth != TSW_unspecified ||
1013 TypeSpecComplex != TSC_unspecified ||
1014 TypeSpecSign != TSS_unspecified ||
1015 TypeAltiVecVector || TypeAltiVecPixel || TypeAltiVecBool ||
1017 const unsigned NumLocs = 9;
1018 SourceLocation ExtraLocs[NumLocs] = {
1019 TSWRange.getBegin(), TSCLoc, TSSLoc,
1020 AltiVecLoc, TQ_constLoc, TQ_restrictLoc,
1021 TQ_volatileLoc, TQ_atomicLoc, TQ_unalignedLoc};
1022 FixItHint Hints[NumLocs];
1023 SourceLocation FirstLoc;
1024 for (unsigned I = 0; I != NumLocs; ++I) {
1025 if (ExtraLocs[I].isValid()) {
1026 if (FirstLoc.isInvalid() ||
1027 S.getSourceManager().isBeforeInTranslationUnit(ExtraLocs[I],
1029 FirstLoc = ExtraLocs[I];
1030 Hints[I] = FixItHint::CreateRemoval(ExtraLocs[I]);
1033 TypeSpecWidth = TSW_unspecified;
1034 TypeSpecComplex = TSC_unspecified;
1035 TypeSpecSign = TSS_unspecified;
1036 TypeAltiVecVector = TypeAltiVecPixel = TypeAltiVecBool = false;
1038 S.Diag(TSTLoc, diag::err_decltype_auto_cannot_be_combined)
1039 << Hints[0] << Hints[1] << Hints[2] << Hints[3]
1040 << Hints[4] << Hints[5] << Hints[6] << Hints[7];
1043 // Validate and finalize AltiVec vector declspec.
1044 if (TypeAltiVecVector) {
1045 if (TypeAltiVecBool) {
1046 // Sign specifiers are not allowed with vector bool. (PIM 2.1)
1047 if (TypeSpecSign != TSS_unspecified) {
1048 S.Diag(TSSLoc, diag::err_invalid_vector_bool_decl_spec)
1049 << getSpecifierName((TSS)TypeSpecSign);
1052 // Only char/int are valid with vector bool. (PIM 2.1)
1053 if (((TypeSpecType != TST_unspecified) && (TypeSpecType != TST_char) &&
1054 (TypeSpecType != TST_int)) || TypeAltiVecPixel) {
1055 S.Diag(TSTLoc, diag::err_invalid_vector_bool_decl_spec)
1056 << (TypeAltiVecPixel ? "__pixel" :
1057 getSpecifierName((TST)TypeSpecType, Policy));
1060 // Only 'short' and 'long long' are valid with vector bool. (PIM 2.1)
1061 if ((TypeSpecWidth != TSW_unspecified) && (TypeSpecWidth != TSW_short) &&
1062 (TypeSpecWidth != TSW_longlong))
1063 S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_bool_decl_spec)
1064 << getSpecifierName((TSW)TypeSpecWidth);
1066 // vector bool long long requires VSX support or ZVector.
1067 if ((TypeSpecWidth == TSW_longlong) &&
1068 (!S.Context.getTargetInfo().hasFeature("vsx")) &&
1069 (!S.Context.getTargetInfo().hasFeature("power8-vector")) &&
1070 !S.getLangOpts().ZVector)
1071 S.Diag(TSTLoc, diag::err_invalid_vector_long_long_decl_spec);
1073 // Elements of vector bool are interpreted as unsigned. (PIM 2.1)
1074 if ((TypeSpecType == TST_char) || (TypeSpecType == TST_int) ||
1075 (TypeSpecWidth != TSW_unspecified))
1076 TypeSpecSign = TSS_unsigned;
1077 } else if (TypeSpecType == TST_double) {
1078 // vector long double and vector long long double are never allowed.
1079 // vector double is OK for Power7 and later, and ZVector.
1080 if (TypeSpecWidth == TSW_long || TypeSpecWidth == TSW_longlong)
1081 S.Diag(TSWRange.getBegin(),
1082 diag::err_invalid_vector_long_double_decl_spec);
1083 else if (!S.Context.getTargetInfo().hasFeature("vsx") &&
1084 !S.getLangOpts().ZVector)
1085 S.Diag(TSTLoc, diag::err_invalid_vector_double_decl_spec);
1086 } else if (TypeSpecType == TST_float) {
1087 // vector float is unsupported for ZVector unless we have the
1088 // vector-enhancements facility 1 (ISA revision 12).
1089 if (S.getLangOpts().ZVector &&
1090 !S.Context.getTargetInfo().hasFeature("arch12"))
1091 S.Diag(TSTLoc, diag::err_invalid_vector_float_decl_spec);
1092 } else if (TypeSpecWidth == TSW_long) {
1093 // vector long is unsupported for ZVector and deprecated for AltiVec.
1094 if (S.getLangOpts().ZVector)
1095 S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_long_decl_spec);
1097 S.Diag(TSWRange.getBegin(),
1098 diag::warn_vector_long_decl_spec_combination)
1099 << getSpecifierName((TST)TypeSpecType, Policy);
1102 if (TypeAltiVecPixel) {
1103 //TODO: perform validation
1104 TypeSpecType = TST_int;
1105 TypeSpecSign = TSS_unsigned;
1106 TypeSpecWidth = TSW_short;
1107 TypeSpecOwned = false;
1111 bool IsFixedPointType =
1112 TypeSpecType == TST_accum || TypeSpecType == TST_fract;
1114 // signed/unsigned are only valid with int/char/wchar_t/_Accum.
1115 if (TypeSpecSign != TSS_unspecified) {
1116 if (TypeSpecType == TST_unspecified)
1117 TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int.
1118 else if (TypeSpecType != TST_int && TypeSpecType != TST_int128 &&
1119 TypeSpecType != TST_char && TypeSpecType != TST_wchar &&
1120 !IsFixedPointType) {
1121 S.Diag(TSSLoc, diag::err_invalid_sign_spec)
1122 << getSpecifierName((TST)TypeSpecType, Policy);
1123 // signed double -> double.
1124 TypeSpecSign = TSS_unspecified;
1128 // Validate the width of the type.
1129 switch (TypeSpecWidth) {
1130 case TSW_unspecified: break;
1131 case TSW_short: // short int
1132 case TSW_longlong: // long long int
1133 if (TypeSpecType == TST_unspecified)
1134 TypeSpecType = TST_int; // short -> short int, long long -> long long int.
1135 else if (!(TypeSpecType == TST_int ||
1136 (IsFixedPointType && TypeSpecWidth != TSW_longlong))) {
1137 S.Diag(TSWRange.getBegin(), diag::err_invalid_width_spec)
1138 << (int)TypeSpecWidth << getSpecifierName((TST)TypeSpecType, Policy);
1139 TypeSpecType = TST_int;
1140 TypeSpecSat = false;
1141 TypeSpecOwned = false;
1144 case TSW_long: // long double, long int
1145 if (TypeSpecType == TST_unspecified)
1146 TypeSpecType = TST_int; // long -> long int.
1147 else if (TypeSpecType != TST_int && TypeSpecType != TST_double &&
1148 !IsFixedPointType) {
1149 S.Diag(TSWRange.getBegin(), diag::err_invalid_width_spec)
1150 << (int)TypeSpecWidth << getSpecifierName((TST)TypeSpecType, Policy);
1151 TypeSpecType = TST_int;
1152 TypeSpecSat = false;
1153 TypeSpecOwned = false;
1158 // TODO: if the implementation does not implement _Complex or _Imaginary,
1159 // disallow their use. Need information about the backend.
1160 if (TypeSpecComplex != TSC_unspecified) {
1161 if (TypeSpecType == TST_unspecified) {
1162 S.Diag(TSCLoc, diag::ext_plain_complex)
1163 << FixItHint::CreateInsertion(
1164 S.getLocForEndOfToken(getTypeSpecComplexLoc()),
1166 TypeSpecType = TST_double; // _Complex -> _Complex double.
1167 } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) {
1168 // Note that this intentionally doesn't include _Complex _Bool.
1169 if (!S.getLangOpts().CPlusPlus)
1170 S.Diag(TSTLoc, diag::ext_integer_complex);
1171 } else if (TypeSpecType != TST_float && TypeSpecType != TST_double) {
1172 S.Diag(TSCLoc, diag::err_invalid_complex_spec)
1173 << getSpecifierName((TST)TypeSpecType, Policy);
1174 TypeSpecComplex = TSC_unspecified;
1178 // C11 6.7.1/3, C++11 [dcl.stc]p1, GNU TLS: __thread, thread_local and
1179 // _Thread_local can only appear with the 'static' and 'extern' storage class
1180 // specifiers. We also allow __private_extern__ as an extension.
1181 if (ThreadStorageClassSpec != TSCS_unspecified) {
1182 switch (StorageClassSpec) {
1183 case SCS_unspecified:
1185 case SCS_private_extern:
1189 if (S.getSourceManager().isBeforeInTranslationUnit(
1190 getThreadStorageClassSpecLoc(), getStorageClassSpecLoc()))
1191 S.Diag(getStorageClassSpecLoc(),
1192 diag::err_invalid_decl_spec_combination)
1193 << DeclSpec::getSpecifierName(getThreadStorageClassSpec())
1194 << SourceRange(getThreadStorageClassSpecLoc());
1196 S.Diag(getThreadStorageClassSpecLoc(),
1197 diag::err_invalid_decl_spec_combination)
1198 << DeclSpec::getSpecifierName(getStorageClassSpec())
1199 << SourceRange(getStorageClassSpecLoc());
1200 // Discard the thread storage class specifier to recover.
1201 ThreadStorageClassSpec = TSCS_unspecified;
1202 ThreadStorageClassSpecLoc = SourceLocation();
1206 // If no type specifier was provided and we're parsing a language where
1207 // the type specifier is not optional, but we got 'auto' as a storage
1208 // class specifier, then assume this is an attempt to use C++0x's 'auto'
1210 if (S.getLangOpts().CPlusPlus &&
1211 TypeSpecType == TST_unspecified && StorageClassSpec == SCS_auto) {
1212 TypeSpecType = TST_auto;
1213 StorageClassSpec = SCS_unspecified;
1214 TSTLoc = TSTNameLoc = StorageClassSpecLoc;
1215 StorageClassSpecLoc = SourceLocation();
1217 // Diagnose if we've recovered from an ill-formed 'auto' storage class
1218 // specifier in a pre-C++11 dialect of C++.
1219 if (!S.getLangOpts().CPlusPlus11 && TypeSpecType == TST_auto)
1220 S.Diag(TSTLoc, diag::ext_auto_type_specifier);
1221 if (S.getLangOpts().CPlusPlus && !S.getLangOpts().CPlusPlus11 &&
1222 StorageClassSpec == SCS_auto)
1223 S.Diag(StorageClassSpecLoc, diag::warn_auto_storage_class)
1224 << FixItHint::CreateRemoval(StorageClassSpecLoc);
1225 if (TypeSpecType == TST_char8)
1226 S.Diag(TSTLoc, diag::warn_cxx17_compat_unicode_type);
1227 else if (TypeSpecType == TST_char16 || TypeSpecType == TST_char32)
1228 S.Diag(TSTLoc, diag::warn_cxx98_compat_unicode_type)
1229 << (TypeSpecType == TST_char16 ? "char16_t" : "char32_t");
1230 if (Constexpr_specified)
1231 S.Diag(ConstexprLoc, diag::warn_cxx98_compat_constexpr);
1233 // C++ [class.friend]p6:
1234 // No storage-class-specifier shall appear in the decl-specifier-seq
1235 // of a friend declaration.
1236 if (isFriendSpecified() &&
1237 (getStorageClassSpec() || getThreadStorageClassSpec())) {
1238 SmallString<32> SpecName;
1239 SourceLocation SCLoc;
1240 FixItHint StorageHint, ThreadHint;
1242 if (DeclSpec::SCS SC = getStorageClassSpec()) {
1243 SpecName = getSpecifierName(SC);
1244 SCLoc = getStorageClassSpecLoc();
1245 StorageHint = FixItHint::CreateRemoval(SCLoc);
1248 if (DeclSpec::TSCS TSC = getThreadStorageClassSpec()) {
1249 if (!SpecName.empty()) SpecName += " ";
1250 SpecName += getSpecifierName(TSC);
1251 SCLoc = getThreadStorageClassSpecLoc();
1252 ThreadHint = FixItHint::CreateRemoval(SCLoc);
1255 S.Diag(SCLoc, diag::err_friend_decl_spec)
1256 << SpecName << StorageHint << ThreadHint;
1258 ClearStorageClassSpecs();
1261 // C++11 [dcl.fct.spec]p5:
1262 // The virtual specifier shall be used only in the initial
1263 // declaration of a non-static class member function;
1264 // C++11 [dcl.fct.spec]p6:
1265 // The explicit specifier shall be used only in the declaration of
1266 // a constructor or conversion function within its class
1268 if (isFriendSpecified() && (isVirtualSpecified() || isExplicitSpecified())) {
1270 SourceLocation SCLoc;
1272 if (isVirtualSpecified()) {
1273 Keyword = "virtual";
1274 SCLoc = getVirtualSpecLoc();
1276 Keyword = "explicit";
1277 SCLoc = getExplicitSpecLoc();
1280 FixItHint Hint = FixItHint::CreateRemoval(SCLoc);
1281 S.Diag(SCLoc, diag::err_friend_decl_spec)
1284 FS_virtual_specified = FS_explicit_specified = false;
1285 FS_virtualLoc = FS_explicitLoc = SourceLocation();
1288 assert(!TypeSpecOwned || isDeclRep((TST) TypeSpecType));
1290 // Okay, now we can infer the real type.
1292 // TODO: return "auto function" and other bad things based on the real type.
1294 // 'data definition has no type or storage class'?
1297 bool DeclSpec::isMissingDeclaratorOk() {
1298 TST tst = getTypeSpecType();
1299 return isDeclRep(tst) && getRepAsDecl() != nullptr &&
1300 StorageClassSpec != DeclSpec::SCS_typedef;
1303 void UnqualifiedId::setOperatorFunctionId(SourceLocation OperatorLoc,
1304 OverloadedOperatorKind Op,
1305 SourceLocation SymbolLocations[3]) {
1306 Kind = UnqualifiedIdKind::IK_OperatorFunctionId;
1307 StartLocation = OperatorLoc;
1308 EndLocation = OperatorLoc;
1309 OperatorFunctionId.Operator = Op;
1310 for (unsigned I = 0; I != 3; ++I) {
1311 OperatorFunctionId.SymbolLocations[I] = SymbolLocations[I].getRawEncoding();
1313 if (SymbolLocations[I].isValid())
1314 EndLocation = SymbolLocations[I];
1318 bool VirtSpecifiers::SetSpecifier(Specifier VS, SourceLocation Loc,
1319 const char *&PrevSpec) {
1320 if (!FirstLocation.isValid())
1321 FirstLocation = Loc;
1325 if (Specifiers & VS) {
1326 PrevSpec = getSpecifierName(VS);
1333 default: llvm_unreachable("Unknown specifier!");
1334 case VS_Override: VS_overrideLoc = Loc; break;
1337 case VS_Final: VS_finalLoc = Loc; break;
1343 const char *VirtSpecifiers::getSpecifierName(Specifier VS) {
1345 default: llvm_unreachable("Unknown specifier");
1346 case VS_Override: return "override";
1347 case VS_Final: return "final";
1348 case VS_GNU_Final: return "__final";
1349 case VS_Sealed: return "sealed";