| 1 | //===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file defines the Sema class, which performs semantic analysis and |
| 10 | // builds ASTs. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_CLANG_SEMA_SEMA_H |
| 15 | #define LLVM_CLANG_SEMA_SEMA_H |
| 16 | |
| 17 | #include "clang/APINotes/APINotesManager.h" |
| 18 | #include "clang/AST/ASTFwd.h" |
| 19 | #include "clang/AST/ASTLambda.h" |
| 20 | #include "clang/AST/Attr.h" |
| 21 | #include "clang/AST/AttrIterator.h" |
| 22 | #include "clang/AST/CharUnits.h" |
| 23 | #include "clang/AST/DeclBase.h" |
| 24 | #include "clang/AST/DeclCXX.h" |
| 25 | #include "clang/AST/DeclTemplate.h" |
| 26 | #include "clang/AST/DeclarationName.h" |
| 27 | #include "clang/AST/Expr.h" |
| 28 | #include "clang/AST/ExprCXX.h" |
| 29 | #include "clang/AST/ExprConcepts.h" |
| 30 | #include "clang/AST/ExternalASTSource.h" |
| 31 | #include "clang/AST/NestedNameSpecifier.h" |
| 32 | #include "clang/AST/OperationKinds.h" |
| 33 | #include "clang/AST/StmtCXX.h" |
| 34 | #include "clang/AST/Type.h" |
| 35 | #include "clang/AST/TypeLoc.h" |
| 36 | #include "clang/Analysis/Analyses/LifetimeSafety/LifetimeAnnotations.h" |
| 37 | #include "clang/Basic/AttrSubjectMatchRules.h" |
| 38 | #include "clang/Basic/Builtins.h" |
| 39 | #include "clang/Basic/CapturedStmt.h" |
| 40 | #include "clang/Basic/Cuda.h" |
| 41 | #include "clang/Basic/DiagnosticSema.h" |
| 42 | #include "clang/Basic/ExceptionSpecificationType.h" |
| 43 | #include "clang/Basic/ExpressionTraits.h" |
| 44 | #include "clang/Basic/LLVM.h" |
| 45 | #include "clang/Basic/Lambda.h" |
| 46 | #include "clang/Basic/LangOptions.h" |
| 47 | #include "clang/Basic/Module.h" |
| 48 | #include "clang/Basic/OpenCLOptions.h" |
| 49 | #include "clang/Basic/OperatorKinds.h" |
| 50 | #include "clang/Basic/PartialDiagnostic.h" |
| 51 | #include "clang/Basic/PragmaKinds.h" |
| 52 | #include "clang/Basic/SourceLocation.h" |
| 53 | #include "clang/Basic/Specifiers.h" |
| 54 | #include "clang/Basic/StackExhaustionHandler.h" |
| 55 | #include "clang/Basic/TemplateKinds.h" |
| 56 | #include "clang/Basic/TokenKinds.h" |
| 57 | #include "clang/Basic/TypeTraits.h" |
| 58 | #include "clang/Sema/AnalysisBasedWarnings.h" |
| 59 | #include "clang/Sema/Attr.h" |
| 60 | #include "clang/Sema/CleanupInfo.h" |
| 61 | #include "clang/Sema/DeclSpec.h" |
| 62 | #include "clang/Sema/ExternalSemaSource.h" |
| 63 | #include "clang/Sema/IdentifierResolver.h" |
| 64 | #include "clang/Sema/Ownership.h" |
| 65 | #include "clang/Sema/ParsedAttr.h" |
| 66 | #include "clang/Sema/Redeclaration.h" |
| 67 | #include "clang/Sema/Scope.h" |
| 68 | #include "clang/Sema/SemaBase.h" |
| 69 | #include "clang/Sema/SemaConcept.h" |
| 70 | #include "clang/Sema/SemaRISCV.h" |
| 71 | #include "clang/Sema/TypoCorrection.h" |
| 72 | #include "clang/Sema/Weak.h" |
| 73 | #include "llvm/ADT/APInt.h" |
| 74 | #include "llvm/ADT/ArrayRef.h" |
| 75 | #include "llvm/ADT/BitmaskEnum.h" |
| 76 | #include "llvm/ADT/DenseMap.h" |
| 77 | #include "llvm/ADT/DenseSet.h" |
| 78 | #include "llvm/ADT/FloatingPointMode.h" |
| 79 | #include "llvm/ADT/FoldingSet.h" |
| 80 | #include "llvm/ADT/MapVector.h" |
| 81 | #include "llvm/ADT/PointerIntPair.h" |
| 82 | #include "llvm/ADT/PointerUnion.h" |
| 83 | #include "llvm/ADT/STLExtras.h" |
| 84 | #include "llvm/ADT/STLForwardCompat.h" |
| 85 | #include "llvm/ADT/STLFunctionalExtras.h" |
| 86 | #include "llvm/ADT/SetVector.h" |
| 87 | #include "llvm/ADT/SmallBitVector.h" |
| 88 | #include "llvm/ADT/SmallPtrSet.h" |
| 89 | #include "llvm/ADT/SmallSet.h" |
| 90 | #include "llvm/ADT/SmallVector.h" |
| 91 | #include "llvm/ADT/StringExtras.h" |
| 92 | #include "llvm/ADT/StringMap.h" |
| 93 | #include "llvm/ADT/TinyPtrVector.h" |
| 94 | #include "llvm/Support/Allocator.h" |
| 95 | #include "llvm/Support/Compiler.h" |
| 96 | #include "llvm/Support/Error.h" |
| 97 | #include "llvm/Support/ErrorHandling.h" |
| 98 | #include <cassert> |
| 99 | #include <climits> |
| 100 | #include <cstddef> |
| 101 | #include <cstdint> |
| 102 | #include <deque> |
| 103 | #include <functional> |
| 104 | #include <iterator> |
| 105 | #include <memory> |
| 106 | #include <optional> |
| 107 | #include <string> |
| 108 | #include <tuple> |
| 109 | #include <type_traits> |
| 110 | #include <utility> |
| 111 | #include <vector> |
| 112 | |
| 113 | namespace llvm { |
| 114 | struct InlineAsmIdentifierInfo; |
| 115 | } // namespace llvm |
| 116 | |
| 117 | namespace clang { |
| 118 | class ADLResult; |
| 119 | class APValue; |
| 120 | struct ASTConstraintSatisfaction; |
| 121 | class ASTConsumer; |
| 122 | class ASTContext; |
| 123 | class ASTDeclReader; |
| 124 | class ASTMutationListener; |
| 125 | class ASTReader; |
| 126 | class ASTWriter; |
| 127 | class CXXBasePath; |
| 128 | class CXXBasePaths; |
| 129 | class CXXFieldCollector; |
| 130 | class CodeCompleteConsumer; |
| 131 | enum class ComparisonCategoryType : unsigned char; |
| 132 | class ConstraintSatisfaction; |
| 133 | class DarwinSDKInfo; |
| 134 | class DeclGroupRef; |
| 135 | class DeducedTemplateArgument; |
| 136 | struct DeductionFailureInfo; |
| 137 | class DependentDiagnostic; |
| 138 | class Designation; |
| 139 | class IdentifierInfo; |
| 140 | class ImplicitConversionSequence; |
| 141 | typedef MutableArrayRef<ImplicitConversionSequence> ConversionSequenceList; |
| 142 | class InitializationKind; |
| 143 | class InitializationSequence; |
| 144 | class InitializedEntity; |
| 145 | enum class LangAS : unsigned int; |
| 146 | class LocalInstantiationScope; |
| 147 | class LookupResult; |
| 148 | class MangleNumberingContext; |
| 149 | typedef ArrayRef<IdentifierLoc> ModuleIdPath; |
| 150 | class ModuleLoader; |
| 151 | class MultiLevelTemplateArgumentList; |
| 152 | struct NormalizedConstraint; |
| 153 | class ObjCInterfaceDecl; |
| 154 | class ObjCMethodDecl; |
| 155 | struct OverloadCandidate; |
| 156 | enum class OverloadCandidateParamOrder : char; |
| 157 | enum OverloadCandidateRewriteKind : unsigned; |
| 158 | class OverloadCandidateSet; |
| 159 | class Preprocessor; |
| 160 | class SemaAMDGPU; |
| 161 | class SemaARM; |
| 162 | class SemaAVR; |
| 163 | class SemaBPF; |
| 164 | class SemaCodeCompletion; |
| 165 | class SemaCUDA; |
| 166 | class SemaDirectX; |
| 167 | class SemaHLSL; |
| 168 | class SemaHexagon; |
| 169 | class SemaLoongArch; |
| 170 | class SemaM68k; |
| 171 | class SemaMIPS; |
| 172 | class SemaMSP430; |
| 173 | class SemaNVPTX; |
| 174 | class SemaObjC; |
| 175 | class SemaOpenACC; |
| 176 | class SemaOpenCL; |
| 177 | class SemaOpenMP; |
| 178 | class SemaPPC; |
| 179 | class SemaPseudoObject; |
| 180 | class SemaRISCV; |
| 181 | class SemaSPIRV; |
| 182 | class SemaSYCL; |
| 183 | class SemaSwift; |
| 184 | class SemaSystemZ; |
| 185 | class SemaWasm; |
| 186 | class SemaX86; |
| 187 | class StandardConversionSequence; |
| 188 | class TemplateArgument; |
| 189 | class TemplateArgumentLoc; |
| 190 | class TemplateInstantiationCallback; |
| 191 | class TemplatePartialOrderingContext; |
| 192 | class TemplateSpecCandidateSet; |
| 193 | class Token; |
| 194 | class TypeConstraint; |
| 195 | class TypoCorrectionConsumer; |
| 196 | class UnresolvedSetImpl; |
| 197 | class UnresolvedSetIterator; |
| 198 | class VisibleDeclConsumer; |
| 199 | |
| 200 | namespace sema { |
| 201 | class BlockScopeInfo; |
| 202 | class Capture; |
| 203 | class CapturedRegionScopeInfo; |
| 204 | class CapturingScopeInfo; |
| 205 | class CompoundScopeInfo; |
| 206 | class DelayedDiagnostic; |
| 207 | class DelayedDiagnosticPool; |
| 208 | class FunctionScopeInfo; |
| 209 | class LambdaScopeInfo; |
| 210 | class SemaPPCallbacks; |
| 211 | class TemplateDeductionInfo; |
| 212 | } // namespace sema |
| 213 | |
| 214 | // AssignmentAction - This is used by all the assignment diagnostic functions |
| 215 | // to represent what is actually causing the operation |
| 216 | enum class AssignmentAction { |
| 217 | Assigning, |
| 218 | Passing, |
| 219 | Returning, |
| 220 | Converting, |
| 221 | Initializing, |
| 222 | Sending, |
| 223 | Casting, |
| 224 | Passing_CFAudited |
| 225 | }; |
| 226 | |
| 227 | namespace threadSafety { |
| 228 | class BeforeSet; |
| 229 | void threadSafetyCleanup(BeforeSet *Cache); |
| 230 | } // namespace threadSafety |
| 231 | |
| 232 | // FIXME: No way to easily map from TemplateTypeParmTypes to |
| 233 | // TemplateTypeParmDecls, so we have this horrible PointerUnion. |
| 234 | typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType *, NamedDecl *, |
| 235 | const TemplateSpecializationType *, |
| 236 | const SubstBuiltinTemplatePackType *>, |
| 237 | SourceLocation> |
| 238 | UnexpandedParameterPack; |
| 239 | |
| 240 | /// Describes whether we've seen any nullability information for the given |
| 241 | /// file. |
| 242 | struct FileNullability { |
| 243 | /// The first pointer declarator (of any pointer kind) in the file that does |
| 244 | /// not have a corresponding nullability annotation. |
| 245 | SourceLocation PointerLoc; |
| 246 | |
| 247 | /// The end location for the first pointer declarator in the file. Used for |
| 248 | /// placing fix-its. |
| 249 | SourceLocation PointerEndLoc; |
| 250 | |
| 251 | /// Which kind of pointer declarator we saw. |
| 252 | uint8_t PointerKind; |
| 253 | |
| 254 | /// Whether we saw any type nullability annotations in the given file. |
| 255 | bool SawTypeNullability = false; |
| 256 | }; |
| 257 | |
| 258 | /// A mapping from file IDs to a record of whether we've seen nullability |
| 259 | /// information in that file. |
| 260 | class FileNullabilityMap { |
| 261 | /// A mapping from file IDs to the nullability information for each file ID. |
| 262 | llvm::DenseMap<FileID, FileNullability> Map; |
| 263 | |
| 264 | /// A single-element cache based on the file ID. |
| 265 | struct { |
| 266 | FileID File; |
| 267 | FileNullability Nullability; |
| 268 | } Cache; |
| 269 | |
| 270 | public: |
| 271 | FileNullability &operator[](FileID file) { |
| 272 | // Check the single-element cache. |
| 273 | if (file == Cache.File) |
| 274 | return Cache.Nullability; |
| 275 | |
| 276 | // It's not in the single-element cache; flush the cache if we have one. |
| 277 | if (!Cache.File.isInvalid()) { |
| 278 | Map[Cache.File] = Cache.Nullability; |
| 279 | } |
| 280 | |
| 281 | // Pull this entry into the cache. |
| 282 | Cache.File = file; |
| 283 | Cache.Nullability = Map[file]; |
| 284 | return Cache.Nullability; |
| 285 | } |
| 286 | }; |
| 287 | |
| 288 | /// Tracks expected type during expression parsing, for use in code completion. |
| 289 | /// The type is tied to a particular token, all functions that update or consume |
| 290 | /// the type take a start location of the token they are looking at as a |
| 291 | /// parameter. This avoids updating the type on hot paths in the parser. |
| 292 | class PreferredTypeBuilder { |
| 293 | public: |
| 294 | PreferredTypeBuilder(ASTContext *Ctx, bool Enabled) |
| 295 | : Ctx(Ctx), Enabled(Enabled) {} |
| 296 | |
| 297 | void enterCondition(Sema &S, SourceLocation Tok); |
| 298 | void enterReturn(Sema &S, SourceLocation Tok); |
| 299 | void enterVariableInit(SourceLocation Tok, Decl *D); |
| 300 | /// Handles e.g. BaseType{ .D = Tok... |
| 301 | void enterDesignatedInitializer(SourceLocation Tok, QualType BaseType, |
| 302 | const Designation &D); |
| 303 | /// Computing a type for the function argument may require running |
| 304 | /// overloading, so we postpone its computation until it is actually needed. |
| 305 | /// |
| 306 | /// Clients should be very careful when using this function, as it stores a |
| 307 | /// function_ref, clients should make sure all calls to get() with the same |
| 308 | /// location happen while function_ref is alive. |
| 309 | /// |
| 310 | /// The callback should also emit signature help as a side-effect, but only |
| 311 | /// if the completion point has been reached. |
| 312 | void enterFunctionArgument(SourceLocation Tok, |
| 313 | llvm::function_ref<QualType()> ComputeType); |
| 314 | |
| 315 | void enterParenExpr(SourceLocation Tok, SourceLocation LParLoc); |
| 316 | void enterUnary(Sema &S, SourceLocation Tok, tok::TokenKind OpKind, |
| 317 | SourceLocation OpLoc); |
| 318 | void enterBinary(Sema &S, SourceLocation Tok, Expr *LHS, tok::TokenKind Op); |
| 319 | void enterMemAccess(Sema &S, SourceLocation Tok, Expr *Base); |
| 320 | void enterSubscript(Sema &S, SourceLocation Tok, Expr *LHS); |
| 321 | /// Handles all type casts, including C-style cast, C++ casts, etc. |
| 322 | void enterTypeCast(SourceLocation Tok, QualType CastType); |
| 323 | |
| 324 | /// Get the expected type associated with this location, if any. |
| 325 | /// |
| 326 | /// If the location is a function argument, determining the expected type |
| 327 | /// involves considering all function overloads and the arguments so far. |
| 328 | /// In this case, signature help for these function overloads will be reported |
| 329 | /// as a side-effect (only if the completion point has been reached). |
| 330 | QualType get(SourceLocation Tok) const { |
| 331 | if (!Enabled || Tok != ExpectedLoc) |
| 332 | return QualType(); |
| 333 | if (!Type.isNull()) |
| 334 | return Type; |
| 335 | if (ComputeType) |
| 336 | return ComputeType(); |
| 337 | return QualType(); |
| 338 | } |
| 339 | |
| 340 | private: |
| 341 | ASTContext *Ctx; |
| 342 | bool Enabled; |
| 343 | /// Start position of a token for which we store expected type. |
| 344 | SourceLocation ExpectedLoc; |
| 345 | /// Expected type for a token starting at ExpectedLoc. |
| 346 | QualType Type; |
| 347 | /// A function to compute expected type at ExpectedLoc. It is only considered |
| 348 | /// if Type is null. |
| 349 | llvm::function_ref<QualType()> ComputeType; |
| 350 | }; |
| 351 | |
| 352 | struct SkipBodyInfo { |
| 353 | SkipBodyInfo() = default; |
| 354 | bool ShouldSkip = false; |
| 355 | bool CheckSameAsPrevious = false; |
| 356 | NamedDecl *Previous = nullptr; |
| 357 | NamedDecl *New = nullptr; |
| 358 | }; |
| 359 | |
| 360 | /// Describes the result of template argument deduction. |
| 361 | /// |
| 362 | /// The TemplateDeductionResult enumeration describes the result of |
| 363 | /// template argument deduction, as returned from |
| 364 | /// DeduceTemplateArguments(). The separate TemplateDeductionInfo |
| 365 | /// structure provides additional information about the results of |
| 366 | /// template argument deduction, e.g., the deduced template argument |
| 367 | /// list (if successful) or the specific template parameters or |
| 368 | /// deduced arguments that were involved in the failure. |
| 369 | enum class TemplateDeductionResult { |
| 370 | /// Template argument deduction was successful. |
| 371 | Success = 0, |
| 372 | /// The declaration was invalid; do nothing. |
| 373 | Invalid, |
| 374 | /// Template argument deduction exceeded the maximum template |
| 375 | /// instantiation depth (which has already been diagnosed). |
| 376 | InstantiationDepth, |
| 377 | /// Template argument deduction did not deduce a value |
| 378 | /// for every template parameter. |
| 379 | Incomplete, |
| 380 | /// Template argument deduction did not deduce a value for every |
| 381 | /// expansion of an expanded template parameter pack. |
| 382 | IncompletePack, |
| 383 | /// Template argument deduction produced inconsistent |
| 384 | /// deduced values for the given template parameter. |
| 385 | Inconsistent, |
| 386 | /// Template argument deduction failed due to inconsistent |
| 387 | /// cv-qualifiers on a template parameter type that would |
| 388 | /// otherwise be deduced, e.g., we tried to deduce T in "const T" |
| 389 | /// but were given a non-const "X". |
| 390 | Underqualified, |
| 391 | /// Substitution of the deduced template argument values |
| 392 | /// resulted in an error. |
| 393 | SubstitutionFailure, |
| 394 | /// After substituting deduced template arguments, a dependent |
| 395 | /// parameter type did not match the corresponding argument. |
| 396 | DeducedMismatch, |
| 397 | /// After substituting deduced template arguments, an element of |
| 398 | /// a dependent parameter type did not match the corresponding element |
| 399 | /// of the corresponding argument (when deducing from an initializer list). |
| 400 | DeducedMismatchNested, |
| 401 | /// A non-depnedent component of the parameter did not match the |
| 402 | /// corresponding component of the argument. |
| 403 | NonDeducedMismatch, |
| 404 | /// When performing template argument deduction for a function |
| 405 | /// template, there were too many call arguments. |
| 406 | TooManyArguments, |
| 407 | /// When performing template argument deduction for a function |
| 408 | /// template, there were too few call arguments. |
| 409 | TooFewArguments, |
| 410 | /// The explicitly-specified template arguments were not valid |
| 411 | /// template arguments for the given template. |
| 412 | InvalidExplicitArguments, |
| 413 | /// Checking non-dependent argument conversions failed. |
| 414 | NonDependentConversionFailure, |
| 415 | /// The deduced arguments did not satisfy the constraints associated |
| 416 | /// with the template. |
| 417 | ConstraintsNotSatisfied, |
| 418 | /// Deduction failed; that's all we know. |
| 419 | MiscellaneousDeductionFailure, |
| 420 | /// CUDA Target attributes do not match. |
| 421 | CUDATargetMismatch, |
| 422 | /// Some error which was already diagnosed. |
| 423 | AlreadyDiagnosed |
| 424 | }; |
| 425 | |
| 426 | /// Kinds of C++ special members. |
| 427 | enum class CXXSpecialMemberKind { |
| 428 | DefaultConstructor, |
| 429 | CopyConstructor, |
| 430 | MoveConstructor, |
| 431 | CopyAssignment, |
| 432 | MoveAssignment, |
| 433 | Destructor, |
| 434 | Invalid |
| 435 | }; |
| 436 | |
| 437 | /// The kind of conversion being performed. |
| 438 | enum class CheckedConversionKind { |
| 439 | /// An implicit conversion. |
| 440 | Implicit, |
| 441 | /// A C-style cast. |
| 442 | CStyleCast, |
| 443 | /// A functional-style cast. |
| 444 | FunctionalCast, |
| 445 | /// A cast other than a C-style cast. |
| 446 | OtherCast, |
| 447 | /// A conversion for an operand of a builtin overloaded operator. |
| 448 | ForBuiltinOverloadedOp |
| 449 | }; |
| 450 | |
| 451 | enum class TagUseKind { |
| 452 | Reference, // Reference to a tag: 'struct foo *X;' |
| 453 | Declaration, // Fwd decl of a tag: 'struct foo;' |
| 454 | Definition, // Definition of a tag: 'struct foo { int X; } Y;' |
| 455 | Friend // Friend declaration: 'friend struct foo;' |
| 456 | }; |
| 457 | |
| 458 | /// Used with attributes/effects with a boolean condition, e.g. `nonblocking`. |
| 459 | enum class FunctionEffectMode : uint8_t { |
| 460 | None, // effect is not present. |
| 461 | False, // effect(false). |
| 462 | True, // effect(true). |
| 463 | Dependent // effect(expr) where expr is dependent. |
| 464 | }; |
| 465 | |
| 466 | /// pragma clang section kind |
| 467 | enum class PragmaClangSectionKind { |
| 468 | Invalid = 0, |
| 469 | BSS = 1, |
| 470 | Data = 2, |
| 471 | Rodata = 3, |
| 472 | Text = 4, |
| 473 | Relro = 5 |
| 474 | }; |
| 475 | |
| 476 | enum class PragmaClangSectionAction { Set = 0, Clear = 1 }; |
| 477 | |
| 478 | enum class PragmaOptionsAlignKind { |
| 479 | Native, // #pragma options align=native |
| 480 | Natural, // #pragma options align=natural |
| 481 | Packed, // #pragma options align=packed |
| 482 | Power, // #pragma options align=power |
| 483 | Mac68k, // #pragma options align=mac68k |
| 484 | Reset // #pragma options align=reset |
| 485 | }; |
| 486 | |
| 487 | enum class TUFragmentKind { |
| 488 | /// The global module fragment, between 'module;' and a module-declaration. |
| 489 | Global, |
| 490 | /// A normal translation unit fragment. For a non-module unit, this is the |
| 491 | /// entire translation unit. Otherwise, it runs from the module-declaration |
| 492 | /// to the private-module-fragment (if any) or the end of the TU (if not). |
| 493 | Normal, |
| 494 | /// The private module fragment, between 'module :private;' and the end of |
| 495 | /// the translation unit. |
| 496 | Private |
| 497 | }; |
| 498 | |
| 499 | enum class FormatStringType { |
| 500 | Scanf, |
| 501 | Printf, |
| 502 | NSString, |
| 503 | Strftime, |
| 504 | Strfmon, |
| 505 | Kprintf, |
| 506 | FreeBSDKPrintf, |
| 507 | OSTrace, |
| 508 | OSLog, |
| 509 | Unknown |
| 510 | }; |
| 511 | |
| 512 | // Used for emitting the right warning by DefaultVariadicArgumentPromotion |
| 513 | enum class VariadicCallType { |
| 514 | Function, |
| 515 | Block, |
| 516 | Method, |
| 517 | Constructor, |
| 518 | DoesNotApply |
| 519 | }; |
| 520 | |
| 521 | enum class BuiltinCountedByRefKind { |
| 522 | Assignment, |
| 523 | Initializer, |
| 524 | FunctionArg, |
| 525 | ReturnArg, |
| 526 | ArraySubscript, |
| 527 | BinaryExpr, |
| 528 | }; |
| 529 | |
| 530 | // Contexts where using non-trivial C union types can be disallowed. This is |
| 531 | // passed to err_non_trivial_c_union_in_invalid_context. |
| 532 | enum class NonTrivialCUnionContext { |
| 533 | // Function parameter. |
| 534 | FunctionParam, |
| 535 | // Function return. |
| 536 | FunctionReturn, |
| 537 | // Default-initialized object. |
| 538 | DefaultInitializedObject, |
| 539 | // Variable with automatic storage duration. |
| 540 | AutoVar, |
| 541 | // Initializer expression that might copy from another object. |
| 542 | CopyInit, |
| 543 | // Assignment. |
| 544 | Assignment, |
| 545 | // Compound literal. |
| 546 | CompoundLiteral, |
| 547 | // Block capture. |
| 548 | BlockCapture, |
| 549 | // lvalue-to-rvalue conversion of volatile type. |
| 550 | LValueToRValueVolatile, |
| 551 | }; |
| 552 | |
| 553 | /// Describes the result of the name lookup and resolution performed |
| 554 | /// by \c Sema::ClassifyName(). |
| 555 | enum class NameClassificationKind { |
| 556 | /// This name is not a type or template in this context, but might be |
| 557 | /// something else. |
| 558 | Unknown, |
| 559 | /// Classification failed; an error has been produced. |
| 560 | Error, |
| 561 | /// The name has been typo-corrected to a keyword. |
| 562 | Keyword, |
| 563 | /// The name was classified as a type. |
| 564 | Type, |
| 565 | /// The name was classified as a specific non-type, non-template |
| 566 | /// declaration. ActOnNameClassifiedAsNonType should be called to |
| 567 | /// convert the declaration to an expression. |
| 568 | NonType, |
| 569 | /// The name was classified as an ADL-only function name. |
| 570 | /// ActOnNameClassifiedAsUndeclaredNonType should be called to convert the |
| 571 | /// result to an expression. |
| 572 | UndeclaredNonType, |
| 573 | /// The name denotes a member of a dependent type that could not be |
| 574 | /// resolved. ActOnNameClassifiedAsDependentNonType should be called to |
| 575 | /// convert the result to an expression. |
| 576 | DependentNonType, |
| 577 | /// The name was classified as an overload set, and an expression |
| 578 | /// representing that overload set has been formed. |
| 579 | /// ActOnNameClassifiedAsOverloadSet should be called to form a suitable |
| 580 | /// expression referencing the overload set. |
| 581 | OverloadSet, |
| 582 | /// The name was classified as a template whose specializations are types. |
| 583 | TypeTemplate, |
| 584 | /// The name was classified as a variable template name. |
| 585 | VarTemplate, |
| 586 | /// The name was classified as a function template name. |
| 587 | FunctionTemplate, |
| 588 | /// The name was classified as an ADL-only function template name. |
| 589 | UndeclaredTemplate, |
| 590 | /// The name was classified as a concept name. |
| 591 | Concept, |
| 592 | }; |
| 593 | |
| 594 | enum class PointerAuthDiscArgKind { |
| 595 | // Address discrimination argument of __ptrauth. |
| 596 | Addr, |
| 597 | |
| 598 | // Extra discriminator argument of __ptrauth. |
| 599 | , |
| 600 | }; |
| 601 | |
| 602 | /// Common ways to introduce type names without a tag for use in diagnostics. |
| 603 | /// Keep in sync with err_tag_reference_non_tag. |
| 604 | enum class NonTagKind { |
| 605 | NonStruct, |
| 606 | NonClass, |
| 607 | NonUnion, |
| 608 | NonEnum, |
| 609 | Typedef, |
| 610 | TypeAlias, |
| 611 | Template, |
| 612 | TypeAliasTemplate, |
| 613 | TemplateTemplateArgument, |
| 614 | }; |
| 615 | |
| 616 | enum class OffsetOfKind { |
| 617 | // Not parsing a type within __builtin_offsetof. |
| 618 | Outside, |
| 619 | // Parsing a type within __builtin_offsetof. |
| 620 | Builtin, |
| 621 | // Parsing a type within macro "offsetof", defined in __buitin_offsetof |
| 622 | // To improve our diagnostic message. |
| 623 | Macro, |
| 624 | }; |
| 625 | |
| 626 | /// Describes the kind of merge to perform for availability |
| 627 | /// attributes (including "deprecated", "unavailable", and "availability"). |
| 628 | enum class AvailabilityMergeKind { |
| 629 | /// Don't merge availability attributes at all. |
| 630 | None, |
| 631 | /// Merge availability attributes for a redeclaration, which requires |
| 632 | /// an exact match. |
| 633 | Redeclaration, |
| 634 | /// Merge availability attributes for an override, which requires |
| 635 | /// an exact match or a weakening of constraints. |
| 636 | Override, |
| 637 | /// Merge availability attributes for an implementation of |
| 638 | /// a protocol requirement. |
| 639 | ProtocolImplementation, |
| 640 | /// Merge availability attributes for an implementation of |
| 641 | /// an optional protocol requirement. |
| 642 | OptionalProtocolImplementation |
| 643 | }; |
| 644 | |
| 645 | enum class TrivialABIHandling { |
| 646 | /// The triviality of a method unaffected by "trivial_abi". |
| 647 | IgnoreTrivialABI, |
| 648 | |
| 649 | /// The triviality of a method affected by "trivial_abi". |
| 650 | ConsiderTrivialABI |
| 651 | }; |
| 652 | |
| 653 | enum class TryCaptureKind { Implicit, ExplicitByVal, ExplicitByRef }; |
| 654 | |
| 655 | enum class AllowFoldKind { |
| 656 | No, |
| 657 | Allow, |
| 658 | }; |
| 659 | |
| 660 | /// Context in which we're performing a usual arithmetic conversion. |
| 661 | enum class ArithConvKind { |
| 662 | /// An arithmetic operation. |
| 663 | Arithmetic, |
| 664 | /// A bitwise operation. |
| 665 | BitwiseOp, |
| 666 | /// A comparison. |
| 667 | Comparison, |
| 668 | /// A conditional (?:) operator. |
| 669 | Conditional, |
| 670 | /// A compound assignment expression. |
| 671 | CompAssign, |
| 672 | }; |
| 673 | |
| 674 | // Used for determining in which context a type is allowed to be passed to a |
| 675 | // vararg function. |
| 676 | enum class VarArgKind { |
| 677 | Valid, |
| 678 | ValidInCXX11, |
| 679 | Undefined, |
| 680 | MSVCUndefined, |
| 681 | Invalid |
| 682 | }; |
| 683 | |
| 684 | /// AssignConvertType - All of the 'assignment' semantic checks return this |
| 685 | /// enum to indicate whether the assignment was allowed. These checks are |
| 686 | /// done for simple assignments, as well as initialization, return from |
| 687 | /// function, argument passing, etc. The query is phrased in terms of a |
| 688 | /// source and destination type. |
| 689 | enum class AssignConvertType { |
| 690 | /// Compatible - the types are compatible according to the standard. |
| 691 | Compatible, |
| 692 | |
| 693 | /// CompatibleVoidPtrToNonVoidPtr - The types are compatible in C because |
| 694 | /// a void * can implicitly convert to another pointer type, which we |
| 695 | /// differentiate for better diagnostic behavior. |
| 696 | CompatibleVoidPtrToNonVoidPtr, |
| 697 | |
| 698 | /// PointerToInt - The assignment converts a pointer to an int, which we |
| 699 | /// accept as an extension. |
| 700 | PointerToInt, |
| 701 | |
| 702 | /// IntToPointer - The assignment converts an int to a pointer, which we |
| 703 | /// accept as an extension. |
| 704 | IntToPointer, |
| 705 | |
| 706 | /// FunctionVoidPointer - The assignment is between a function pointer and |
| 707 | /// void*, which the standard doesn't allow, but we accept as an extension. |
| 708 | FunctionVoidPointer, |
| 709 | |
| 710 | /// IncompatiblePointer - The assignment is between two pointers types that |
| 711 | /// are not compatible, but we accept them as an extension. |
| 712 | IncompatiblePointer, |
| 713 | |
| 714 | /// IncompatibleFunctionPointer - The assignment is between two function |
| 715 | /// pointers types that are not compatible, but we accept them as an |
| 716 | /// extension. |
| 717 | IncompatibleFunctionPointer, |
| 718 | |
| 719 | /// IncompatibleFunctionPointerStrict - The assignment is between two |
| 720 | /// function pointer types that are not identical, but are compatible, |
| 721 | /// unless compiled with -fsanitize=cfi, in which case the type mismatch |
| 722 | /// may trip an indirect call runtime check. |
| 723 | IncompatibleFunctionPointerStrict, |
| 724 | |
| 725 | /// IncompatiblePointerSign - The assignment is between two pointers types |
| 726 | /// which point to integers which have a different sign, but are otherwise |
| 727 | /// identical. This is a subset of the above, but broken out because it's by |
| 728 | /// far the most common case of incompatible pointers. |
| 729 | IncompatiblePointerSign, |
| 730 | |
| 731 | /// CompatiblePointerDiscardsQualifiers - The assignment discards |
| 732 | /// c/v/r qualifiers, which we accept as an extension. |
| 733 | CompatiblePointerDiscardsQualifiers, |
| 734 | |
| 735 | /// IncompatiblePointerDiscardsQualifiers - The assignment |
| 736 | /// discards qualifiers that we don't permit to be discarded, |
| 737 | /// like address spaces. |
| 738 | IncompatiblePointerDiscardsQualifiers, |
| 739 | |
| 740 | /// IncompatiblePointerDiscardsOverflowBehavior - The assignment |
| 741 | /// discards overflow behavior annotations between otherwise compatible |
| 742 | /// pointer types. |
| 743 | IncompatiblePointerDiscardsOverflowBehavior, |
| 744 | |
| 745 | /// IncompatibleNestedPointerAddressSpaceMismatch - The assignment |
| 746 | /// changes address spaces in nested pointer types which is not allowed. |
| 747 | /// For instance, converting __private int ** to __generic int ** is |
| 748 | /// illegal even though __private could be converted to __generic. |
| 749 | IncompatibleNestedPointerAddressSpaceMismatch, |
| 750 | |
| 751 | /// IncompatibleNestedPointerQualifiers - The assignment is between two |
| 752 | /// nested pointer types, and the qualifiers other than the first two |
| 753 | /// levels differ e.g. char ** -> const char **, but we accept them as an |
| 754 | /// extension. |
| 755 | IncompatibleNestedPointerQualifiers, |
| 756 | |
| 757 | /// IncompatibleVectors - The assignment is between two vector types that |
| 758 | /// have the same size, which we accept as an extension. |
| 759 | IncompatibleVectors, |
| 760 | |
| 761 | /// IntToBlockPointer - The assignment converts an int to a block |
| 762 | /// pointer. We disallow this. |
| 763 | IntToBlockPointer, |
| 764 | |
| 765 | /// IncompatibleBlockPointer - The assignment is between two block |
| 766 | /// pointers types that are not compatible. |
| 767 | IncompatibleBlockPointer, |
| 768 | |
| 769 | /// IncompatibleObjCQualifiedId - The assignment is between a qualified |
| 770 | /// id type and something else (that is incompatible with it). For example, |
| 771 | /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. |
| 772 | IncompatibleObjCQualifiedId, |
| 773 | |
| 774 | /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an |
| 775 | /// object with __weak qualifier. |
| 776 | IncompatibleObjCWeakRef, |
| 777 | |
| 778 | /// IncompatibleOBTKinds - Assigning between incompatible OverflowBehaviorType |
| 779 | /// kinds, e.g., from __ob_trap to __ob_wrap or vice versa. |
| 780 | IncompatibleOBTKinds, |
| 781 | |
| 782 | /// CompatibleOBTDiscards - Assignment discards overflow behavior |
| 783 | CompatibleOBTDiscards, |
| 784 | |
| 785 | /// Incompatible - We reject this conversion outright, it is invalid to |
| 786 | /// represent it in the AST. |
| 787 | Incompatible |
| 788 | }; |
| 789 | |
| 790 | /// The scope in which to find allocation functions. |
| 791 | enum class AllocationFunctionScope { |
| 792 | /// Only look for allocation functions in the global scope. |
| 793 | Global, |
| 794 | /// Only look for allocation functions in the scope of the |
| 795 | /// allocated class. |
| 796 | Class, |
| 797 | /// Look for allocation functions in both the global scope |
| 798 | /// and in the scope of the allocated class. |
| 799 | Both |
| 800 | }; |
| 801 | |
| 802 | /// Describes the result of an "if-exists" condition check. |
| 803 | enum class IfExistsResult { |
| 804 | /// The symbol exists. |
| 805 | Exists, |
| 806 | |
| 807 | /// The symbol does not exist. |
| 808 | DoesNotExist, |
| 809 | |
| 810 | /// The name is a dependent name, so the results will differ |
| 811 | /// from one instantiation to the next. |
| 812 | Dependent, |
| 813 | |
| 814 | /// An error occurred. |
| 815 | Error |
| 816 | }; |
| 817 | |
| 818 | enum class CorrectTypoKind { |
| 819 | NonError, // CorrectTypo used in a non error recovery situation. |
| 820 | ErrorRecovery // CorrectTypo used in normal error recovery. |
| 821 | }; |
| 822 | |
| 823 | enum class OverloadKind { |
| 824 | /// This is a legitimate overload: the existing declarations are |
| 825 | /// functions or function templates with different signatures. |
| 826 | Overload, |
| 827 | |
| 828 | /// This is not an overload because the signature exactly matches |
| 829 | /// an existing declaration. |
| 830 | Match, |
| 831 | |
| 832 | /// This is not an overload because the lookup results contain a |
| 833 | /// non-function. |
| 834 | NonFunction |
| 835 | }; |
| 836 | |
| 837 | /// Contexts in which a converted constant expression is required. |
| 838 | enum class CCEKind { |
| 839 | CaseValue, ///< Expression in a case label. |
| 840 | Enumerator, ///< Enumerator value with fixed underlying type. |
| 841 | TemplateArg, ///< Value of a non-type template parameter. |
| 842 | TempArgStrict, ///< As above, but applies strict template checking |
| 843 | ///< rules. |
| 844 | ArrayBound, ///< Array bound in array declarator or new-expression. |
| 845 | ExplicitBool, ///< Condition in an explicit(bool) specifier. |
| 846 | Noexcept, ///< Condition in a noexcept(bool) specifier. |
| 847 | StaticAssertMessageSize, ///< Call to size() in a static assert |
| 848 | ///< message. |
| 849 | StaticAssertMessageData, ///< Call to data() in a static assert |
| 850 | ///< message. |
| 851 | }; |
| 852 | |
| 853 | /// Enums for the diagnostics of target, target_version and target_clones. |
| 854 | namespace DiagAttrParams { |
| 855 | enum DiagType { Unsupported, Duplicate, Unknown }; |
| 856 | enum Specifier { None, CPU, Tune }; |
| 857 | enum AttrName { Target, TargetClones, TargetVersion }; |
| 858 | } // end namespace DiagAttrParams |
| 859 | |
| 860 | void inferNoReturnAttr(Sema &S, Decl *D); |
| 861 | |
| 862 | #ifdef __GNUC__ |
| 863 | #pragma GCC diagnostic push |
| 864 | #pragma GCC diagnostic ignored "-Wattributes" |
| 865 | #endif |
| 866 | /// Sema - This implements semantic analysis and AST building for C. |
| 867 | /// \nosubgrouping |
| 868 | class Sema final : public SemaBase { |
| 869 | #ifdef __GNUC__ |
| 870 | #pragma GCC diagnostic pop |
| 871 | #endif |
| 872 | // Table of Contents |
| 873 | // ----------------- |
| 874 | // 1. Semantic Analysis (Sema.cpp) |
| 875 | // 2. API Notes (SemaAPINotes.cpp) |
| 876 | // 3. C++ Access Control (SemaAccess.cpp) |
| 877 | // 4. Attributes (SemaAttr.cpp) |
| 878 | // 5. Availability Attribute Handling (SemaAvailability.cpp) |
| 879 | // 6. Bounds Safety (SemaBoundsSafety.cpp) |
| 880 | // 7. Casts (SemaCast.cpp) |
| 881 | // 8. Extra Semantic Checking (SemaChecking.cpp) |
| 882 | // 9. C++ Coroutines (SemaCoroutine.cpp) |
| 883 | // 10. C++ Scope Specifiers (SemaCXXScopeSpec.cpp) |
| 884 | // 11. Declarations (SemaDecl.cpp) |
| 885 | // 12. Declaration Attribute Handling (SemaDeclAttr.cpp) |
| 886 | // 13. C++ Declarations (SemaDeclCXX.cpp) |
| 887 | // 14. C++ Exception Specifications (SemaExceptionSpec.cpp) |
| 888 | // 15. Expressions (SemaExpr.cpp) |
| 889 | // 16. C++ Expressions (SemaExprCXX.cpp) |
| 890 | // 17. Member Access Expressions (SemaExprMember.cpp) |
| 891 | // 18. Initializers (SemaInit.cpp) |
| 892 | // 19. C++ Lambda Expressions (SemaLambda.cpp) |
| 893 | // 20. Name Lookup (SemaLookup.cpp) |
| 894 | // 21. Modules (SemaModule.cpp) |
| 895 | // 22. C++ Overloading (SemaOverload.cpp) |
| 896 | // 23. Statements (SemaStmt.cpp) |
| 897 | // 24. `inline asm` Statement (SemaStmtAsm.cpp) |
| 898 | // 25. Statement Attribute Handling (SemaStmtAttr.cpp) |
| 899 | // 26. C++ Templates (SemaTemplate.cpp) |
| 900 | // 27. C++ Template Argument Deduction (SemaTemplateDeduction.cpp) |
| 901 | // 28. C++ Template Deduction Guide (SemaTemplateDeductionGuide.cpp) |
| 902 | // 29. C++ Template Instantiation (SemaTemplateInstantiate.cpp) |
| 903 | // 30. C++ Template Declaration Instantiation |
| 904 | // (SemaTemplateInstantiateDecl.cpp) |
| 905 | // 31. C++ Variadic Templates (SemaTemplateVariadic.cpp) |
| 906 | // 32. Constraints and Concepts (SemaConcept.cpp) |
| 907 | // 33. Types (SemaType.cpp) |
| 908 | // 34. FixIt Helpers (SemaFixItUtils.cpp) |
| 909 | // 35. Function Effects (SemaFunctionEffects.cpp) |
| 910 | |
| 911 | /// \name Semantic Analysis |
| 912 | /// Implementations are in Sema.cpp |
| 913 | ///@{ |
| 914 | |
| 915 | public: |
| 916 | Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, |
| 917 | TranslationUnitKind TUKind = TU_Complete, |
| 918 | CodeCompleteConsumer *CompletionConsumer = nullptr); |
| 919 | ~Sema(); |
| 920 | |
| 921 | /// Perform initialization that occurs after the parser has been |
| 922 | /// initialized but before it parses anything. |
| 923 | void Initialize(); |
| 924 | |
| 925 | /// This virtual key function only exists to limit the emission of debug info |
| 926 | /// describing the Sema class. GCC and Clang only emit debug info for a class |
| 927 | /// with a vtable when the vtable is emitted. Sema is final and not |
| 928 | /// polymorphic, but the debug info size savings are so significant that it is |
| 929 | /// worth adding a vtable just to take advantage of this optimization. |
| 930 | LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION(); |
| 931 | |
| 932 | const LangOptions &getLangOpts() const { return LangOpts; } |
| 933 | OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; } |
| 934 | FPOptions &getCurFPFeatures() { return CurFPFeatures; } |
| 935 | |
| 936 | DiagnosticsEngine &getDiagnostics() const { return Diags; } |
| 937 | SourceManager &getSourceManager() const { return SourceMgr; } |
| 938 | Preprocessor &getPreprocessor() const { return PP; } |
| 939 | ASTContext &getASTContext() const { return Context; } |
| 940 | ASTConsumer &getASTConsumer() const { return Consumer; } |
| 941 | ASTMutationListener *getASTMutationListener() const; |
| 942 | ExternalSemaSource *getExternalSource() const { return ExternalSource.get(); } |
| 943 | |
| 944 | DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking(SourceLocation Loc, |
| 945 | StringRef Platform); |
| 946 | DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking(); |
| 947 | |
| 948 | /// Registers an external source. If an external source already exists, |
| 949 | /// creates a multiplex external source and appends to it. |
| 950 | /// |
| 951 | ///\param[in] E - A non-null external sema source. |
| 952 | /// |
| 953 | void addExternalSource(IntrusiveRefCntPtr<ExternalSemaSource> E); |
| 954 | |
| 955 | /// Print out statistics about the semantic analysis. |
| 956 | void PrintStats() const; |
| 957 | |
| 958 | /// Run some code with "sufficient" stack space. (Currently, at least 256K is |
| 959 | /// guaranteed). Produces a warning if we're low on stack space and allocates |
| 960 | /// more in that case. Use this in code that may recurse deeply (for example, |
| 961 | /// in template instantiation) to avoid stack overflow. |
| 962 | void runWithSufficientStackSpace(SourceLocation Loc, |
| 963 | llvm::function_ref<void()> Fn); |
| 964 | |
| 965 | /// Returns default addr space for method qualifiers. |
| 966 | LangAS getDefaultCXXMethodAddrSpace() const; |
| 967 | |
| 968 | /// Load weak undeclared identifiers from the external source. |
| 969 | void LoadExternalWeakUndeclaredIdentifiers(); |
| 970 | |
| 971 | /// Determine if VD, which must be a variable or function, is an external |
| 972 | /// symbol that nonetheless can't be referenced from outside this translation |
| 973 | /// unit because its type has no linkage and it's not extern "C". |
| 974 | bool isExternalWithNoLinkageType(const ValueDecl *VD) const; |
| 975 | |
| 976 | /// Obtain a sorted list of functions that are undefined but ODR-used. |
| 977 | void getUndefinedButUsed( |
| 978 | SmallVectorImpl<std::pair<NamedDecl *, SourceLocation>> &Undefined); |
| 979 | |
| 980 | typedef std::pair<SourceLocation, bool> DeleteExprLoc; |
| 981 | typedef llvm::SmallVector<DeleteExprLoc, 4> DeleteLocs; |
| 982 | /// Retrieves list of suspicious delete-expressions that will be checked at |
| 983 | /// the end of translation unit. |
| 984 | const llvm::MapVector<FieldDecl *, DeleteLocs> & |
| 985 | getMismatchingDeleteExpressions() const; |
| 986 | |
| 987 | /// Cause the built diagnostic to be emitted on the DiagosticsEngine. |
| 988 | /// This is closely coupled to the SemaDiagnosticBuilder class and |
| 989 | /// should not be used elsewhere. |
| 990 | void EmitDiagnostic(unsigned DiagID, const DiagnosticBuilder &DB); |
| 991 | |
| 992 | void addImplicitTypedef(StringRef Name, QualType T); |
| 993 | |
| 994 | /// Whether uncompilable error has occurred. This includes error happens |
| 995 | /// in deferred diagnostics. |
| 996 | bool hasUncompilableErrorOccurred() const; |
| 997 | |
| 998 | /// Looks through the macro-expansion chain for the given |
| 999 | /// location, looking for a macro expansion with the given name. |
| 1000 | /// If one is found, returns true and sets the location to that |
| 1001 | /// expansion loc. |
| 1002 | bool findMacroSpelling(SourceLocation &loc, StringRef name); |
| 1003 | |
| 1004 | /// Calls \c Lexer::getLocForEndOfToken() |
| 1005 | SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0); |
| 1006 | |
| 1007 | /// Calls \c Lexer::findNextToken() to find the next token, and if the |
| 1008 | /// locations of both ends of the token can be resolved it return that |
| 1009 | /// range; Otherwise it returns an invalid SourceRange. |
| 1010 | SourceRange getRangeForNextToken( |
| 1011 | SourceLocation Loc, bool IncludeMacros, bool , |
| 1012 | std::optional<tok::TokenKind> ExpectedToken = std::nullopt); |
| 1013 | |
| 1014 | /// Retrieve the module loader associated with the preprocessor. |
| 1015 | ModuleLoader &getModuleLoader() const; |
| 1016 | |
| 1017 | /// Invent a new identifier for parameters of abbreviated templates. |
| 1018 | IdentifierInfo * |
| 1019 | InventAbbreviatedTemplateParameterTypeName(const IdentifierInfo *ParamName, |
| 1020 | unsigned Index); |
| 1021 | |
| 1022 | void emitAndClearUnusedLocalTypedefWarnings(); |
| 1023 | |
| 1024 | // Emit all deferred diagnostics. |
| 1025 | void emitDeferredDiags(); |
| 1026 | |
| 1027 | /// This is called before the very first declaration in the translation unit |
| 1028 | /// is parsed. Note that the ASTContext may have already injected some |
| 1029 | /// declarations. |
| 1030 | void ActOnStartOfTranslationUnit(); |
| 1031 | /// ActOnEndOfTranslationUnit - This is called at the very end of the |
| 1032 | /// translation unit when EOF is reached and all but the top-level scope is |
| 1033 | /// popped. |
| 1034 | void ActOnEndOfTranslationUnit(); |
| 1035 | void ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind); |
| 1036 | |
| 1037 | /// Determines the active Scope associated with the given declaration |
| 1038 | /// context. |
| 1039 | /// |
| 1040 | /// This routine maps a declaration context to the active Scope object that |
| 1041 | /// represents that declaration context in the parser. It is typically used |
| 1042 | /// from "scope-less" code (e.g., template instantiation, lazy creation of |
| 1043 | /// declarations) that injects a name for name-lookup purposes and, therefore, |
| 1044 | /// must update the Scope. |
| 1045 | /// |
| 1046 | /// \returns The scope corresponding to the given declaraion context, or NULL |
| 1047 | /// if no such scope is open. |
| 1048 | Scope *getScopeForContext(DeclContext *Ctx); |
| 1049 | |
| 1050 | void PushFunctionScope(); |
| 1051 | void PushBlockScope(Scope *BlockScope, BlockDecl *Block); |
| 1052 | sema::LambdaScopeInfo *PushLambdaScope(); |
| 1053 | |
| 1054 | /// This is used to inform Sema what the current TemplateParameterDepth |
| 1055 | /// is during Parsing. Currently it is used to pass on the depth |
| 1056 | /// when parsing generic lambda 'auto' parameters. |
| 1057 | void RecordParsingTemplateParameterDepth(unsigned Depth); |
| 1058 | |
| 1059 | void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD, |
| 1060 | RecordDecl *RD, CapturedRegionKind K, |
| 1061 | unsigned OpenMPCaptureLevel = 0); |
| 1062 | |
| 1063 | /// Custom deleter to allow FunctionScopeInfos to be kept alive for a short |
| 1064 | /// time after they've been popped. |
| 1065 | class PoppedFunctionScopeDeleter { |
| 1066 | Sema *Self; |
| 1067 | |
| 1068 | public: |
| 1069 | explicit PoppedFunctionScopeDeleter(Sema *Self) : Self(Self) {} |
| 1070 | void operator()(sema::FunctionScopeInfo *Scope) const; |
| 1071 | }; |
| 1072 | |
| 1073 | using PoppedFunctionScopePtr = |
| 1074 | std::unique_ptr<sema::FunctionScopeInfo, PoppedFunctionScopeDeleter>; |
| 1075 | |
| 1076 | /// Pop a function (or block or lambda or captured region) scope from the |
| 1077 | /// stack. |
| 1078 | /// |
| 1079 | /// \param WP The warning policy to use for CFG-based warnings, or null if |
| 1080 | /// such warnings should not be produced. |
| 1081 | /// \param D The declaration corresponding to this function scope, if |
| 1082 | /// producing CFG-based warnings. |
| 1083 | /// \param BlockType The type of the block expression, if D is a BlockDecl. |
| 1084 | PoppedFunctionScopePtr |
| 1085 | PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP = nullptr, |
| 1086 | Decl *D = nullptr, QualType BlockType = QualType()); |
| 1087 | |
| 1088 | sema::FunctionScopeInfo *getEnclosingFunction() const; |
| 1089 | |
| 1090 | void setFunctionHasBranchIntoScope(); |
| 1091 | void setFunctionHasBranchProtectedScope(); |
| 1092 | void setFunctionHasIndirectGoto(); |
| 1093 | void setFunctionHasMustTail(); |
| 1094 | |
| 1095 | void PushCompoundScope(bool IsStmtExpr); |
| 1096 | void PopCompoundScope(); |
| 1097 | |
| 1098 | /// Determine whether any errors occurred within this function/method/ |
| 1099 | /// block. |
| 1100 | bool hasAnyUnrecoverableErrorsInThisFunction() const; |
| 1101 | |
| 1102 | /// Retrieve the current block, if any. |
| 1103 | sema::BlockScopeInfo *getCurBlock(); |
| 1104 | |
| 1105 | /// Get the innermost lambda or block enclosing the current location, if any. |
| 1106 | /// This looks through intervening non-lambda, non-block scopes such as local |
| 1107 | /// functions. |
| 1108 | sema::CapturingScopeInfo *getEnclosingLambdaOrBlock() const; |
| 1109 | |
| 1110 | /// Retrieve the current lambda scope info, if any. |
| 1111 | /// \param IgnoreNonLambdaCapturingScope true if should find the top-most |
| 1112 | /// lambda scope info ignoring all inner capturing scopes that are not |
| 1113 | /// lambda scopes. |
| 1114 | sema::LambdaScopeInfo * |
| 1115 | getCurLambda(bool IgnoreNonLambdaCapturingScope = false); |
| 1116 | |
| 1117 | /// Retrieve the current generic lambda info, if any. |
| 1118 | sema::LambdaScopeInfo *getCurGenericLambda(); |
| 1119 | |
| 1120 | /// Retrieve the current captured region, if any. |
| 1121 | sema::CapturedRegionScopeInfo *getCurCapturedRegion(); |
| 1122 | |
| 1123 | void (SourceRange ); |
| 1124 | |
| 1125 | /// Retrieve the parser's current scope. |
| 1126 | /// |
| 1127 | /// This routine must only be used when it is certain that semantic analysis |
| 1128 | /// and the parser are in precisely the same context, which is not the case |
| 1129 | /// when, e.g., we are performing any kind of template instantiation. |
| 1130 | /// Therefore, the only safe places to use this scope are in the parser |
| 1131 | /// itself and in routines directly invoked from the parser and *never* from |
| 1132 | /// template substitution or instantiation. |
| 1133 | Scope *getCurScope() const { return CurScope; } |
| 1134 | |
| 1135 | IdentifierInfo *getSuperIdentifier() const; |
| 1136 | |
| 1137 | DeclContext *getCurLexicalContext() const { |
| 1138 | return OriginalLexicalContext ? OriginalLexicalContext : CurContext; |
| 1139 | } |
| 1140 | |
| 1141 | SemaDiagnosticBuilder targetDiag(SourceLocation Loc, unsigned DiagID, |
| 1142 | const FunctionDecl *FD = nullptr); |
| 1143 | SemaDiagnosticBuilder targetDiag(SourceLocation Loc, |
| 1144 | const PartialDiagnostic &PD, |
| 1145 | const FunctionDecl *FD = nullptr) { |
| 1146 | return targetDiag(Loc, DiagID: PD.getDiagID(), FD) << PD; |
| 1147 | } |
| 1148 | |
| 1149 | /// Check if the type is allowed to be used for the current target. |
| 1150 | void checkTypeSupport(QualType Ty, SourceLocation Loc, |
| 1151 | ValueDecl *D = nullptr); |
| 1152 | |
| 1153 | /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit |
| 1154 | /// cast. If there is already an implicit cast, merge into the existing one. |
| 1155 | /// If isLvalue, the result of the cast is an lvalue. |
| 1156 | ExprResult ImpCastExprToType( |
| 1157 | Expr *E, QualType Type, CastKind CK, ExprValueKind VK = VK_PRValue, |
| 1158 | const CXXCastPath *BasePath = nullptr, |
| 1159 | CheckedConversionKind CCK = CheckedConversionKind::Implicit); |
| 1160 | |
| 1161 | /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding |
| 1162 | /// to the conversion from scalar type ScalarTy to the Boolean type. |
| 1163 | static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy); |
| 1164 | |
| 1165 | /// If \p AllowLambda is true, treat lambda as function. |
| 1166 | DeclContext *getFunctionLevelDeclContext(bool AllowLambda = false) const; |
| 1167 | |
| 1168 | /// Returns a pointer to the innermost enclosing function, or nullptr if the |
| 1169 | /// current context is not inside a function. If \p AllowLambda is true, |
| 1170 | /// this can return the call operator of an enclosing lambda, otherwise |
| 1171 | /// lambdas are skipped when looking for an enclosing function. |
| 1172 | FunctionDecl *getCurFunctionDecl(bool AllowLambda = false) const; |
| 1173 | |
| 1174 | /// getCurMethodDecl - If inside of a method body, this returns a pointer to |
| 1175 | /// the method decl for the method being parsed. If we're currently |
| 1176 | /// in a 'block', this returns the containing context. |
| 1177 | ObjCMethodDecl *getCurMethodDecl(); |
| 1178 | |
| 1179 | /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method |
| 1180 | /// or C function we're in, otherwise return null. If we're currently |
| 1181 | /// in a 'block', this returns the containing context. |
| 1182 | NamedDecl *getCurFunctionOrMethodDecl() const; |
| 1183 | |
| 1184 | /// Warn if we're implicitly casting from a _Nullable pointer type to a |
| 1185 | /// _Nonnull one. |
| 1186 | void diagnoseNullableToNonnullConversion(QualType DstType, QualType SrcType, |
| 1187 | SourceLocation Loc); |
| 1188 | |
| 1189 | /// Warn when implicitly casting 0 to nullptr. |
| 1190 | void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E); |
| 1191 | |
| 1192 | /// Warn when implicitly changing function effects. |
| 1193 | void diagnoseFunctionEffectConversion(QualType DstType, QualType SrcType, |
| 1194 | SourceLocation Loc); |
| 1195 | |
| 1196 | /// makeUnavailableInSystemHeader - There is an error in the current |
| 1197 | /// context. If we're still in a system header, and we can plausibly |
| 1198 | /// make the relevant declaration unavailable instead of erroring, do |
| 1199 | /// so and return true. |
| 1200 | bool (SourceLocation loc, |
| 1201 | UnavailableAttr::ImplicitReason reason); |
| 1202 | |
| 1203 | /// Retrieve a suitable printing policy for diagnostics. |
| 1204 | PrintingPolicy getPrintingPolicy() const { |
| 1205 | return getPrintingPolicy(Ctx: Context, PP); |
| 1206 | } |
| 1207 | |
| 1208 | /// Retrieve a suitable printing policy for diagnostics. |
| 1209 | static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx, |
| 1210 | const Preprocessor &PP); |
| 1211 | |
| 1212 | /// Scope actions. |
| 1213 | void ActOnTranslationUnitScope(Scope *S); |
| 1214 | |
| 1215 | /// Determine whether \param D is function like (function or function |
| 1216 | /// template) for parsing. |
| 1217 | bool isDeclaratorFunctionLike(Declarator &D); |
| 1218 | |
| 1219 | /// The maximum alignment, same as in llvm::Value. We duplicate them here |
| 1220 | /// because that allows us not to duplicate the constants in clang code, |
| 1221 | /// which we must to since we can't directly use the llvm constants. |
| 1222 | /// The value is verified against llvm here: lib/CodeGen/CGDecl.cpp |
| 1223 | /// |
| 1224 | /// This is the greatest alignment value supported by load, store, and alloca |
| 1225 | /// instructions, and global values. |
| 1226 | static const unsigned MaxAlignmentExponent = 32; |
| 1227 | static const uint64_t MaximumAlignment = 1ull << MaxAlignmentExponent; |
| 1228 | |
| 1229 | /// Flag indicating whether or not to collect detailed statistics. |
| 1230 | bool CollectStats; |
| 1231 | |
| 1232 | std::unique_ptr<sema::FunctionScopeInfo> CachedFunctionScope; |
| 1233 | |
| 1234 | /// Stack containing information about each of the nested |
| 1235 | /// function, block, and method scopes that are currently active. |
| 1236 | SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes; |
| 1237 | |
| 1238 | /// The index of the first FunctionScope that corresponds to the current |
| 1239 | /// context. |
| 1240 | unsigned FunctionScopesStart = 0; |
| 1241 | |
| 1242 | /// Track the number of currently active capturing scopes. |
| 1243 | unsigned CapturingFunctionScopes = 0; |
| 1244 | |
| 1245 | llvm::BumpPtrAllocator BumpAlloc; |
| 1246 | |
| 1247 | /// The kind of translation unit we are processing. |
| 1248 | /// |
| 1249 | /// When we're processing a complete translation unit, Sema will perform |
| 1250 | /// end-of-translation-unit semantic tasks (such as creating |
| 1251 | /// initializers for tentative definitions in C) once parsing has |
| 1252 | /// completed. Modules and precompiled headers perform different kinds of |
| 1253 | /// checks. |
| 1254 | const TranslationUnitKind TUKind; |
| 1255 | |
| 1256 | /// Translation Unit Scope - useful to Objective-C actions that need |
| 1257 | /// to lookup file scope declarations in the "ordinary" C decl namespace. |
| 1258 | /// For example, user-defined classes, built-in "id" type, etc. |
| 1259 | Scope *TUScope; |
| 1260 | |
| 1261 | void incrementMSManglingNumber() const { |
| 1262 | return CurScope->incrementMSManglingNumber(); |
| 1263 | } |
| 1264 | |
| 1265 | /// Try to recover by turning the given expression into a |
| 1266 | /// call. Returns true if recovery was attempted or an error was |
| 1267 | /// emitted; this may also leave the ExprResult invalid. |
| 1268 | bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD, |
| 1269 | bool ForceComplain = false, |
| 1270 | bool (*IsPlausibleResult)(QualType) = nullptr); |
| 1271 | |
| 1272 | // Adds implicit lifetime bound attribute for implicit this to its |
| 1273 | // TypeSourceInfo. |
| 1274 | void addLifetimeBoundToImplicitThis(CXXMethodDecl *MD); |
| 1275 | |
| 1276 | /// Figure out if an expression could be turned into a call. |
| 1277 | /// |
| 1278 | /// Use this when trying to recover from an error where the programmer may |
| 1279 | /// have written just the name of a function instead of actually calling it. |
| 1280 | /// |
| 1281 | /// \param E - The expression to examine. |
| 1282 | /// \param ZeroArgCallReturnTy - If the expression can be turned into a call |
| 1283 | /// with no arguments, this parameter is set to the type returned by such a |
| 1284 | /// call; otherwise, it is set to an empty QualType. |
| 1285 | /// \param OverloadSet - If the expression is an overloaded function |
| 1286 | /// name, this parameter is populated with the decls of the various |
| 1287 | /// overloads. |
| 1288 | bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy, |
| 1289 | UnresolvedSetImpl &NonTemplateOverloads); |
| 1290 | |
| 1291 | typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; |
| 1292 | typedef OpaquePtr<TemplateName> TemplateTy; |
| 1293 | typedef OpaquePtr<QualType> TypeTy; |
| 1294 | |
| 1295 | OpenCLOptions OpenCLFeatures; |
| 1296 | FPOptions CurFPFeatures; |
| 1297 | |
| 1298 | const LangOptions &LangOpts; |
| 1299 | Preprocessor &PP; |
| 1300 | ASTContext &Context; |
| 1301 | ASTConsumer &Consumer; |
| 1302 | DiagnosticsEngine &Diags; |
| 1303 | SourceManager &SourceMgr; |
| 1304 | api_notes::APINotesManager APINotes; |
| 1305 | |
| 1306 | /// A RAII object to enter scope of a compound statement. |
| 1307 | class CompoundScopeRAII { |
| 1308 | public: |
| 1309 | CompoundScopeRAII(Sema &S, bool IsStmtExpr = false) : S(S) { |
| 1310 | S.ActOnStartOfCompoundStmt(IsStmtExpr); |
| 1311 | } |
| 1312 | |
| 1313 | ~CompoundScopeRAII() { S.ActOnFinishOfCompoundStmt(); } |
| 1314 | CompoundScopeRAII(const CompoundScopeRAII &) = delete; |
| 1315 | CompoundScopeRAII &operator=(const CompoundScopeRAII &) = delete; |
| 1316 | |
| 1317 | private: |
| 1318 | Sema &S; |
| 1319 | }; |
| 1320 | |
| 1321 | /// An RAII helper that pops function a function scope on exit. |
| 1322 | struct FunctionScopeRAII { |
| 1323 | Sema &S; |
| 1324 | bool Active; |
| 1325 | FunctionScopeRAII(Sema &S) : S(S), Active(true) {} |
| 1326 | ~FunctionScopeRAII() { |
| 1327 | if (Active) |
| 1328 | S.PopFunctionScopeInfo(); |
| 1329 | } |
| 1330 | void disable() { Active = false; } |
| 1331 | }; |
| 1332 | |
| 1333 | sema::FunctionScopeInfo *getCurFunction() const { |
| 1334 | return FunctionScopes.empty() ? nullptr : FunctionScopes.back(); |
| 1335 | } |
| 1336 | |
| 1337 | /// Worker object for performing CFG-based warnings. |
| 1338 | sema::AnalysisBasedWarnings AnalysisWarnings; |
| 1339 | threadSafety::BeforeSet *ThreadSafetyDeclCache; |
| 1340 | |
| 1341 | /// Callback to the parser to parse templated functions when needed. |
| 1342 | typedef void LateTemplateParserCB(void *P, LateParsedTemplate &LPT); |
| 1343 | LateTemplateParserCB *LateTemplateParser; |
| 1344 | void *OpaqueParser; |
| 1345 | |
| 1346 | void SetLateTemplateParser(LateTemplateParserCB *LTP, void *P) { |
| 1347 | LateTemplateParser = LTP; |
| 1348 | OpaqueParser = P; |
| 1349 | } |
| 1350 | |
| 1351 | /// Callback to the parser to parse a type expressed as a string. |
| 1352 | std::function<TypeResult(StringRef, StringRef, SourceLocation)> |
| 1353 | ParseTypeFromStringCallback; |
| 1354 | |
| 1355 | /// VAListTagName - The declaration name corresponding to __va_list_tag. |
| 1356 | /// This is used as part of a hack to omit that class from ADL results. |
| 1357 | DeclarationName VAListTagName; |
| 1358 | |
| 1359 | /// Is the last error level diagnostic immediate. This is used to determined |
| 1360 | /// whether the next info diagnostic should be immediate. |
| 1361 | bool IsLastErrorImmediate = true; |
| 1362 | |
| 1363 | /// Track if we're currently analyzing overflow behavior types in assignment |
| 1364 | /// context. |
| 1365 | bool InOverflowBehaviorAssignmentContext = false; |
| 1366 | |
| 1367 | class DelayedDiagnostics; |
| 1368 | |
| 1369 | class DelayedDiagnosticsState { |
| 1370 | sema::DelayedDiagnosticPool *SavedPool = nullptr; |
| 1371 | friend class Sema::DelayedDiagnostics; |
| 1372 | }; |
| 1373 | typedef DelayedDiagnosticsState ParsingDeclState; |
| 1374 | typedef DelayedDiagnosticsState ProcessingContextState; |
| 1375 | |
| 1376 | /// A class which encapsulates the logic for delaying diagnostics |
| 1377 | /// during parsing and other processing. |
| 1378 | class DelayedDiagnostics { |
| 1379 | /// The current pool of diagnostics into which delayed |
| 1380 | /// diagnostics should go. |
| 1381 | sema::DelayedDiagnosticPool *CurPool = nullptr; |
| 1382 | |
| 1383 | public: |
| 1384 | DelayedDiagnostics() = default; |
| 1385 | |
| 1386 | /// Adds a delayed diagnostic. |
| 1387 | void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h |
| 1388 | |
| 1389 | /// Determines whether diagnostics should be delayed. |
| 1390 | bool shouldDelayDiagnostics() { return CurPool != nullptr; } |
| 1391 | |
| 1392 | /// Returns the current delayed-diagnostics pool. |
| 1393 | sema::DelayedDiagnosticPool *getCurrentPool() const { return CurPool; } |
| 1394 | |
| 1395 | /// Enter a new scope. Access and deprecation diagnostics will be |
| 1396 | /// collected in this pool. |
| 1397 | DelayedDiagnosticsState push(sema::DelayedDiagnosticPool &pool) { |
| 1398 | DelayedDiagnosticsState state; |
| 1399 | state.SavedPool = CurPool; |
| 1400 | CurPool = &pool; |
| 1401 | return state; |
| 1402 | } |
| 1403 | |
| 1404 | /// Leave a delayed-diagnostic state that was previously pushed. |
| 1405 | /// Do not emit any of the diagnostics. This is performed as part |
| 1406 | /// of the bookkeeping of popping a pool "properly". |
| 1407 | void popWithoutEmitting(DelayedDiagnosticsState state) { |
| 1408 | CurPool = state.SavedPool; |
| 1409 | } |
| 1410 | |
| 1411 | /// Enter a new scope where access and deprecation diagnostics are |
| 1412 | /// not delayed. |
| 1413 | DelayedDiagnosticsState pushUndelayed() { |
| 1414 | DelayedDiagnosticsState state; |
| 1415 | state.SavedPool = CurPool; |
| 1416 | CurPool = nullptr; |
| 1417 | return state; |
| 1418 | } |
| 1419 | |
| 1420 | /// Undo a previous pushUndelayed(). |
| 1421 | void popUndelayed(DelayedDiagnosticsState state) { |
| 1422 | assert(CurPool == nullptr); |
| 1423 | CurPool = state.SavedPool; |
| 1424 | } |
| 1425 | } DelayedDiagnostics; |
| 1426 | |
| 1427 | ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) { |
| 1428 | return DelayedDiagnostics.push(pool); |
| 1429 | } |
| 1430 | |
| 1431 | /// Diagnostics that are emitted only if we discover that the given function |
| 1432 | /// must be codegen'ed. Because handling these correctly adds overhead to |
| 1433 | /// compilation, this is currently only enabled for CUDA compilations. |
| 1434 | SemaDiagnosticBuilder::DeferredDiagnosticsType DeviceDeferredDiags; |
| 1435 | |
| 1436 | /// CurContext - This is the current declaration context of parsing. |
| 1437 | DeclContext *CurContext; |
| 1438 | |
| 1439 | SemaAMDGPU &AMDGPU() { |
| 1440 | assert(AMDGPUPtr); |
| 1441 | return *AMDGPUPtr; |
| 1442 | } |
| 1443 | |
| 1444 | SemaARM &ARM() { |
| 1445 | assert(ARMPtr); |
| 1446 | return *ARMPtr; |
| 1447 | } |
| 1448 | |
| 1449 | SemaAVR &AVR() { |
| 1450 | assert(AVRPtr); |
| 1451 | return *AVRPtr; |
| 1452 | } |
| 1453 | |
| 1454 | SemaBPF &BPF() { |
| 1455 | assert(BPFPtr); |
| 1456 | return *BPFPtr; |
| 1457 | } |
| 1458 | |
| 1459 | SemaCodeCompletion &CodeCompletion() { |
| 1460 | assert(CodeCompletionPtr); |
| 1461 | return *CodeCompletionPtr; |
| 1462 | } |
| 1463 | |
| 1464 | SemaCUDA &CUDA() { |
| 1465 | assert(CUDAPtr); |
| 1466 | return *CUDAPtr; |
| 1467 | } |
| 1468 | |
| 1469 | SemaDirectX &DirectX() { |
| 1470 | assert(DirectXPtr); |
| 1471 | return *DirectXPtr; |
| 1472 | } |
| 1473 | |
| 1474 | SemaHLSL &HLSL() { |
| 1475 | assert(HLSLPtr); |
| 1476 | return *HLSLPtr; |
| 1477 | } |
| 1478 | |
| 1479 | SemaHexagon &Hexagon() { |
| 1480 | assert(HexagonPtr); |
| 1481 | return *HexagonPtr; |
| 1482 | } |
| 1483 | |
| 1484 | SemaLoongArch &LoongArch() { |
| 1485 | assert(LoongArchPtr); |
| 1486 | return *LoongArchPtr; |
| 1487 | } |
| 1488 | |
| 1489 | SemaM68k &M68k() { |
| 1490 | assert(M68kPtr); |
| 1491 | return *M68kPtr; |
| 1492 | } |
| 1493 | |
| 1494 | SemaMIPS &MIPS() { |
| 1495 | assert(MIPSPtr); |
| 1496 | return *MIPSPtr; |
| 1497 | } |
| 1498 | |
| 1499 | SemaMSP430 &MSP430() { |
| 1500 | assert(MSP430Ptr); |
| 1501 | return *MSP430Ptr; |
| 1502 | } |
| 1503 | |
| 1504 | SemaNVPTX &NVPTX() { |
| 1505 | assert(NVPTXPtr); |
| 1506 | return *NVPTXPtr; |
| 1507 | } |
| 1508 | |
| 1509 | SemaObjC &ObjC() { |
| 1510 | assert(ObjCPtr); |
| 1511 | return *ObjCPtr; |
| 1512 | } |
| 1513 | |
| 1514 | SemaOpenACC &OpenACC() { |
| 1515 | assert(OpenACCPtr); |
| 1516 | return *OpenACCPtr; |
| 1517 | } |
| 1518 | |
| 1519 | SemaOpenCL &OpenCL() { |
| 1520 | assert(OpenCLPtr); |
| 1521 | return *OpenCLPtr; |
| 1522 | } |
| 1523 | |
| 1524 | SemaOpenMP &OpenMP() { |
| 1525 | assert(OpenMPPtr && "SemaOpenMP is dead" ); |
| 1526 | return *OpenMPPtr; |
| 1527 | } |
| 1528 | |
| 1529 | SemaPPC &PPC() { |
| 1530 | assert(PPCPtr); |
| 1531 | return *PPCPtr; |
| 1532 | } |
| 1533 | |
| 1534 | SemaPseudoObject &PseudoObject() { |
| 1535 | assert(PseudoObjectPtr); |
| 1536 | return *PseudoObjectPtr; |
| 1537 | } |
| 1538 | |
| 1539 | SemaRISCV &RISCV() { |
| 1540 | assert(RISCVPtr); |
| 1541 | return *RISCVPtr; |
| 1542 | } |
| 1543 | |
| 1544 | SemaSPIRV &SPIRV() { |
| 1545 | assert(SPIRVPtr); |
| 1546 | return *SPIRVPtr; |
| 1547 | } |
| 1548 | |
| 1549 | SemaSYCL &SYCL() { |
| 1550 | assert(SYCLPtr); |
| 1551 | return *SYCLPtr; |
| 1552 | } |
| 1553 | |
| 1554 | SemaSwift &Swift() { |
| 1555 | assert(SwiftPtr); |
| 1556 | return *SwiftPtr; |
| 1557 | } |
| 1558 | |
| 1559 | SemaSystemZ &SystemZ() { |
| 1560 | assert(SystemZPtr); |
| 1561 | return *SystemZPtr; |
| 1562 | } |
| 1563 | |
| 1564 | SemaWasm &Wasm() { |
| 1565 | assert(WasmPtr); |
| 1566 | return *WasmPtr; |
| 1567 | } |
| 1568 | |
| 1569 | SemaX86 &X86() { |
| 1570 | assert(X86Ptr); |
| 1571 | return *X86Ptr; |
| 1572 | } |
| 1573 | |
| 1574 | /// Source of additional semantic information. |
| 1575 | IntrusiveRefCntPtr<ExternalSemaSource> ExternalSource; |
| 1576 | |
| 1577 | protected: |
| 1578 | friend class Parser; |
| 1579 | friend class InitializationSequence; |
| 1580 | friend class ASTReader; |
| 1581 | friend class ASTDeclReader; |
| 1582 | friend class ASTWriter; |
| 1583 | |
| 1584 | private: |
| 1585 | std::optional<std::unique_ptr<DarwinSDKInfo>> CachedDarwinSDKInfo; |
| 1586 | bool WarnedDarwinSDKInfoMissing = false; |
| 1587 | |
| 1588 | StackExhaustionHandler StackHandler; |
| 1589 | |
| 1590 | Sema(const Sema &) = delete; |
| 1591 | void operator=(const Sema &) = delete; |
| 1592 | |
| 1593 | /// The handler for the FileChanged preprocessor events. |
| 1594 | /// |
| 1595 | /// Used for diagnostics that implement custom semantic analysis for #include |
| 1596 | /// directives, like -Wpragma-pack. |
| 1597 | sema::SemaPPCallbacks *SemaPPCallbackHandler; |
| 1598 | |
| 1599 | /// The parser's current scope. |
| 1600 | /// |
| 1601 | /// The parser maintains this state here. |
| 1602 | Scope *CurScope; |
| 1603 | |
| 1604 | mutable IdentifierInfo *Ident_super; |
| 1605 | |
| 1606 | std::unique_ptr<SemaAMDGPU> AMDGPUPtr; |
| 1607 | std::unique_ptr<SemaARM> ARMPtr; |
| 1608 | std::unique_ptr<SemaAVR> AVRPtr; |
| 1609 | std::unique_ptr<SemaBPF> BPFPtr; |
| 1610 | std::unique_ptr<SemaCodeCompletion> CodeCompletionPtr; |
| 1611 | std::unique_ptr<SemaCUDA> CUDAPtr; |
| 1612 | std::unique_ptr<SemaDirectX> DirectXPtr; |
| 1613 | std::unique_ptr<SemaHLSL> HLSLPtr; |
| 1614 | std::unique_ptr<SemaHexagon> HexagonPtr; |
| 1615 | std::unique_ptr<SemaLoongArch> LoongArchPtr; |
| 1616 | std::unique_ptr<SemaM68k> M68kPtr; |
| 1617 | std::unique_ptr<SemaMIPS> MIPSPtr; |
| 1618 | std::unique_ptr<SemaMSP430> MSP430Ptr; |
| 1619 | std::unique_ptr<SemaNVPTX> NVPTXPtr; |
| 1620 | std::unique_ptr<SemaObjC> ObjCPtr; |
| 1621 | std::unique_ptr<SemaOpenACC> OpenACCPtr; |
| 1622 | std::unique_ptr<SemaOpenCL> OpenCLPtr; |
| 1623 | std::unique_ptr<SemaOpenMP> OpenMPPtr; |
| 1624 | std::unique_ptr<SemaPPC> PPCPtr; |
| 1625 | std::unique_ptr<SemaPseudoObject> PseudoObjectPtr; |
| 1626 | std::unique_ptr<SemaRISCV> RISCVPtr; |
| 1627 | std::unique_ptr<SemaSPIRV> SPIRVPtr; |
| 1628 | std::unique_ptr<SemaSYCL> SYCLPtr; |
| 1629 | std::unique_ptr<SemaSwift> SwiftPtr; |
| 1630 | std::unique_ptr<SemaSystemZ> SystemZPtr; |
| 1631 | std::unique_ptr<SemaWasm> WasmPtr; |
| 1632 | std::unique_ptr<SemaX86> X86Ptr; |
| 1633 | |
| 1634 | ///@} |
| 1635 | |
| 1636 | // |
| 1637 | // |
| 1638 | // ------------------------------------------------------------------------- |
| 1639 | // |
| 1640 | // |
| 1641 | |
| 1642 | /// \name API Notes |
| 1643 | /// Implementations are in SemaAPINotes.cpp |
| 1644 | ///@{ |
| 1645 | |
| 1646 | public: |
| 1647 | /// Map any API notes provided for this declaration to attributes on the |
| 1648 | /// declaration. |
| 1649 | /// |
| 1650 | /// Triggered by declaration-attribute processing. |
| 1651 | void ProcessAPINotes(Decl *D); |
| 1652 | /// Apply the 'Nullability:' annotation to the specified declaration |
| 1653 | void ApplyNullability(Decl *D, NullabilityKind Nullability); |
| 1654 | /// Apply the 'Type:' annotation to the specified declaration |
| 1655 | void ApplyAPINotesType(Decl *D, StringRef TypeString); |
| 1656 | |
| 1657 | /// Whether APINotes should be gathered for all applicable Swift language |
| 1658 | /// versions, without being applied. Leaving clients of the current module |
| 1659 | /// to select and apply the correct version. |
| 1660 | bool captureSwiftVersionIndependentAPINotes() { |
| 1661 | return APINotes.captureVersionIndependentSwift(); |
| 1662 | } |
| 1663 | ///@} |
| 1664 | |
| 1665 | // |
| 1666 | // |
| 1667 | // ------------------------------------------------------------------------- |
| 1668 | // |
| 1669 | // |
| 1670 | |
| 1671 | /// \name C++ Access Control |
| 1672 | /// Implementations are in SemaAccess.cpp |
| 1673 | ///@{ |
| 1674 | |
| 1675 | public: |
| 1676 | enum AccessResult { |
| 1677 | AR_accessible, |
| 1678 | AR_inaccessible, |
| 1679 | AR_dependent, |
| 1680 | AR_delayed |
| 1681 | }; |
| 1682 | |
| 1683 | /// SetMemberAccessSpecifier - Set the access specifier of a member. |
| 1684 | /// Returns true on error (when the previous member decl access specifier |
| 1685 | /// is different from the new member decl access specifier). |
| 1686 | bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, |
| 1687 | NamedDecl *PrevMemberDecl, |
| 1688 | AccessSpecifier LexicalAS); |
| 1689 | |
| 1690 | /// Perform access-control checking on a previously-unresolved member |
| 1691 | /// access which has now been resolved to a member. |
| 1692 | AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, |
| 1693 | DeclAccessPair FoundDecl); |
| 1694 | AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, |
| 1695 | DeclAccessPair FoundDecl); |
| 1696 | |
| 1697 | /// Checks access to an overloaded operator new or delete. |
| 1698 | AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, |
| 1699 | SourceRange PlacementRange, |
| 1700 | CXXRecordDecl *NamingClass, |
| 1701 | DeclAccessPair FoundDecl, |
| 1702 | bool Diagnose = true); |
| 1703 | |
| 1704 | /// Checks access to a constructor. |
| 1705 | AccessResult CheckConstructorAccess(SourceLocation Loc, CXXConstructorDecl *D, |
| 1706 | DeclAccessPair FoundDecl, |
| 1707 | const InitializedEntity &Entity, |
| 1708 | bool IsCopyBindingRefToTemp = false); |
| 1709 | |
| 1710 | /// Checks access to a constructor. |
| 1711 | AccessResult CheckConstructorAccess(SourceLocation Loc, CXXConstructorDecl *D, |
| 1712 | DeclAccessPair FoundDecl, |
| 1713 | const InitializedEntity &Entity, |
| 1714 | const PartialDiagnostic &PDiag); |
| 1715 | AccessResult CheckDestructorAccess(SourceLocation Loc, |
| 1716 | CXXDestructorDecl *Dtor, |
| 1717 | const PartialDiagnostic &PDiag, |
| 1718 | QualType objectType = QualType()); |
| 1719 | |
| 1720 | /// Checks access to the target of a friend declaration. |
| 1721 | AccessResult CheckFriendAccess(NamedDecl *D); |
| 1722 | |
| 1723 | /// Checks access to a member. |
| 1724 | AccessResult CheckMemberAccess(SourceLocation UseLoc, |
| 1725 | CXXRecordDecl *NamingClass, |
| 1726 | DeclAccessPair Found); |
| 1727 | |
| 1728 | /// Checks implicit access to a member in a structured binding. |
| 1729 | AccessResult |
| 1730 | CheckStructuredBindingMemberAccess(SourceLocation UseLoc, |
| 1731 | CXXRecordDecl *DecomposedClass, |
| 1732 | DeclAccessPair Field); |
| 1733 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr, |
| 1734 | const SourceRange &, |
| 1735 | DeclAccessPair FoundDecl); |
| 1736 | |
| 1737 | /// Checks access to an overloaded member operator, including |
| 1738 | /// conversion operators. |
| 1739 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr, |
| 1740 | Expr *ArgExpr, |
| 1741 | DeclAccessPair FoundDecl); |
| 1742 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr, |
| 1743 | ArrayRef<Expr *> ArgExprs, |
| 1744 | DeclAccessPair FoundDecl); |
| 1745 | AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, |
| 1746 | DeclAccessPair FoundDecl); |
| 1747 | |
| 1748 | /// Checks access for a hierarchy conversion. |
| 1749 | /// |
| 1750 | /// \param ForceCheck true if this check should be performed even if access |
| 1751 | /// control is disabled; some things rely on this for semantics |
| 1752 | /// \param ForceUnprivileged true if this check should proceed as if the |
| 1753 | /// context had no special privileges |
| 1754 | AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, QualType Base, |
| 1755 | QualType Derived, const CXXBasePath &Path, |
| 1756 | unsigned DiagID, bool ForceCheck = false, |
| 1757 | bool ForceUnprivileged = false); |
| 1758 | |
| 1759 | AccessResult CheckBaseClassAccess( |
| 1760 | SourceLocation AccessLoc, CXXRecordDecl *Base, CXXRecordDecl *Derived, |
| 1761 | const CXXBasePath &Path, unsigned DiagID, |
| 1762 | llvm::function_ref<void(PartialDiagnostic &PD)> SetupPDiag, |
| 1763 | bool ForceCheck = false, bool ForceUnprivileged = false); |
| 1764 | |
| 1765 | /// Checks access to all the declarations in the given result set. |
| 1766 | void CheckLookupAccess(const LookupResult &R); |
| 1767 | |
| 1768 | /// Checks access to Target from the given class. The check will take access |
| 1769 | /// specifiers into account, but no member access expressions and such. |
| 1770 | /// |
| 1771 | /// \param Target the declaration to check if it can be accessed |
| 1772 | /// \param NamingClass the class in which the lookup was started. |
| 1773 | /// \param BaseType type of the left side of member access expression. |
| 1774 | /// \p BaseType and \p NamingClass are used for C++ access control. |
| 1775 | /// Depending on the lookup case, they should be set to the following: |
| 1776 | /// - lhs.target (member access without a qualifier): |
| 1777 | /// \p BaseType and \p NamingClass are both the type of 'lhs'. |
| 1778 | /// - lhs.X::target (member access with a qualifier): |
| 1779 | /// BaseType is the type of 'lhs', NamingClass is 'X' |
| 1780 | /// - X::target (qualified lookup without member access): |
| 1781 | /// BaseType is null, NamingClass is 'X'. |
| 1782 | /// - target (unqualified lookup). |
| 1783 | /// BaseType is null, NamingClass is the parent class of 'target'. |
| 1784 | /// \return true if the Target is accessible from the Class, false otherwise. |
| 1785 | bool IsSimplyAccessible(NamedDecl *Decl, CXXRecordDecl *NamingClass, |
| 1786 | QualType BaseType); |
| 1787 | |
| 1788 | /// Is the given member accessible for the purposes of deciding whether to |
| 1789 | /// define a special member function as deleted? |
| 1790 | bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass, |
| 1791 | DeclAccessPair Found, QualType ObjectType, |
| 1792 | SourceLocation Loc, |
| 1793 | const PartialDiagnostic &Diag); |
| 1794 | bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass, |
| 1795 | DeclAccessPair Found, |
| 1796 | QualType ObjectType) { |
| 1797 | return isMemberAccessibleForDeletion(NamingClass, Found, ObjectType, |
| 1798 | Loc: SourceLocation(), Diag: PDiag()); |
| 1799 | } |
| 1800 | |
| 1801 | void HandleDependentAccessCheck( |
| 1802 | const DependentDiagnostic &DD, |
| 1803 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 1804 | void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); |
| 1805 | |
| 1806 | ///@} |
| 1807 | |
| 1808 | // |
| 1809 | // |
| 1810 | // ------------------------------------------------------------------------- |
| 1811 | // |
| 1812 | // |
| 1813 | |
| 1814 | /// \name Attributes |
| 1815 | /// Implementations are in SemaAttr.cpp |
| 1816 | ///@{ |
| 1817 | |
| 1818 | public: |
| 1819 | /// Controls member pointer representation format under the MS ABI. |
| 1820 | LangOptions::PragmaMSPointersToMembersKind |
| 1821 | MSPointerToMemberRepresentationMethod; |
| 1822 | |
| 1823 | bool MSStructPragmaOn; // True when \#pragma ms_struct on |
| 1824 | |
| 1825 | /// Source location for newly created implicit MSInheritanceAttrs |
| 1826 | SourceLocation ImplicitMSInheritanceAttrLoc; |
| 1827 | |
| 1828 | struct PragmaClangSection { |
| 1829 | std::string SectionName; |
| 1830 | bool Valid = false; |
| 1831 | SourceLocation PragmaLocation; |
| 1832 | }; |
| 1833 | |
| 1834 | PragmaClangSection PragmaClangBSSSection; |
| 1835 | PragmaClangSection PragmaClangDataSection; |
| 1836 | PragmaClangSection PragmaClangRodataSection; |
| 1837 | PragmaClangSection PragmaClangRelroSection; |
| 1838 | PragmaClangSection PragmaClangTextSection; |
| 1839 | |
| 1840 | enum PragmaMsStackAction { |
| 1841 | PSK_Reset = 0x0, // #pragma () |
| 1842 | PSK_Set = 0x1, // #pragma (value) |
| 1843 | PSK_Push = 0x2, // #pragma (push[, id]) |
| 1844 | PSK_Pop = 0x4, // #pragma (pop[, id]) |
| 1845 | PSK_Show = 0x8, // #pragma (show) -- only for "pack"! |
| 1846 | PSK_Push_Set = PSK_Push | PSK_Set, // #pragma (push[, id], value) |
| 1847 | PSK_Pop_Set = PSK_Pop | PSK_Set, // #pragma (pop[, id], value) |
| 1848 | }; |
| 1849 | |
| 1850 | struct PragmaPackInfo { |
| 1851 | PragmaMsStackAction Action; |
| 1852 | StringRef SlotLabel; |
| 1853 | Token Alignment; |
| 1854 | }; |
| 1855 | |
| 1856 | // #pragma pack and align. |
| 1857 | class AlignPackInfo { |
| 1858 | public: |
| 1859 | // `Native` represents default align mode, which may vary based on the |
| 1860 | // platform. |
| 1861 | enum Mode : unsigned char { Native, Natural, Packed, Mac68k }; |
| 1862 | |
| 1863 | // #pragma pack info constructor |
| 1864 | AlignPackInfo(AlignPackInfo::Mode M, unsigned Num, bool IsXL) |
| 1865 | : PackAttr(true), AlignMode(M), PackNumber(Num), XLStack(IsXL) { |
| 1866 | assert(Num == PackNumber && "The pack number has been truncated." ); |
| 1867 | } |
| 1868 | |
| 1869 | // #pragma align info constructor |
| 1870 | AlignPackInfo(AlignPackInfo::Mode M, bool IsXL) |
| 1871 | : PackAttr(false), AlignMode(M), |
| 1872 | PackNumber(M == Packed ? 1 : UninitPackVal), XLStack(IsXL) {} |
| 1873 | |
| 1874 | explicit AlignPackInfo(bool IsXL) : AlignPackInfo(Native, IsXL) {} |
| 1875 | |
| 1876 | AlignPackInfo() : AlignPackInfo(Native, false) {} |
| 1877 | |
| 1878 | // When a AlignPackInfo itself cannot be used, this returns an 32-bit |
| 1879 | // integer encoding for it. This should only be passed to |
| 1880 | // AlignPackInfo::getFromRawEncoding, it should not be inspected directly. |
| 1881 | static uint32_t getRawEncoding(const AlignPackInfo &Info) { |
| 1882 | std::uint32_t Encoding{}; |
| 1883 | if (Info.IsXLStack()) |
| 1884 | Encoding |= IsXLMask; |
| 1885 | |
| 1886 | Encoding |= static_cast<uint32_t>(Info.getAlignMode()) << 1; |
| 1887 | |
| 1888 | if (Info.IsPackAttr()) |
| 1889 | Encoding |= PackAttrMask; |
| 1890 | |
| 1891 | Encoding |= static_cast<uint32_t>(Info.getPackNumber()) << 4; |
| 1892 | |
| 1893 | return Encoding; |
| 1894 | } |
| 1895 | |
| 1896 | static AlignPackInfo getFromRawEncoding(unsigned Encoding) { |
| 1897 | bool IsXL = static_cast<bool>(Encoding & IsXLMask); |
| 1898 | AlignPackInfo::Mode M = |
| 1899 | static_cast<AlignPackInfo::Mode>((Encoding & AlignModeMask) >> 1); |
| 1900 | int PackNumber = (Encoding & PackNumMask) >> 4; |
| 1901 | |
| 1902 | if (Encoding & PackAttrMask) |
| 1903 | return AlignPackInfo(M, PackNumber, IsXL); |
| 1904 | |
| 1905 | return AlignPackInfo(M, IsXL); |
| 1906 | } |
| 1907 | |
| 1908 | bool IsPackAttr() const { return PackAttr; } |
| 1909 | |
| 1910 | bool IsAlignAttr() const { return !PackAttr; } |
| 1911 | |
| 1912 | Mode getAlignMode() const { return AlignMode; } |
| 1913 | |
| 1914 | unsigned getPackNumber() const { return PackNumber; } |
| 1915 | |
| 1916 | bool IsPackSet() const { |
| 1917 | // #pragma align, #pragma pack(), and #pragma pack(0) do not set the pack |
| 1918 | // attriute on a decl. |
| 1919 | return PackNumber != UninitPackVal && PackNumber != 0; |
| 1920 | } |
| 1921 | |
| 1922 | bool IsXLStack() const { return XLStack; } |
| 1923 | |
| 1924 | bool operator==(const AlignPackInfo &Info) const { |
| 1925 | return std::tie(args: AlignMode, args: PackNumber, args: PackAttr, args: XLStack) == |
| 1926 | std::tie(args: Info.AlignMode, args: Info.PackNumber, args: Info.PackAttr, |
| 1927 | args: Info.XLStack); |
| 1928 | } |
| 1929 | |
| 1930 | bool operator!=(const AlignPackInfo &Info) const { |
| 1931 | return !(*this == Info); |
| 1932 | } |
| 1933 | |
| 1934 | private: |
| 1935 | /// \brief True if this is a pragma pack attribute, |
| 1936 | /// not a pragma align attribute. |
| 1937 | bool PackAttr; |
| 1938 | |
| 1939 | /// \brief The alignment mode that is in effect. |
| 1940 | Mode AlignMode; |
| 1941 | |
| 1942 | /// \brief The pack number of the stack. |
| 1943 | unsigned char PackNumber; |
| 1944 | |
| 1945 | /// \brief True if it is a XL #pragma align/pack stack. |
| 1946 | bool XLStack; |
| 1947 | |
| 1948 | /// \brief Uninitialized pack value. |
| 1949 | static constexpr unsigned char UninitPackVal = -1; |
| 1950 | |
| 1951 | // Masks to encode and decode an AlignPackInfo. |
| 1952 | static constexpr uint32_t IsXLMask{0x0000'0001}; |
| 1953 | static constexpr uint32_t AlignModeMask{0x0000'0006}; |
| 1954 | static constexpr uint32_t PackAttrMask{0x00000'0008}; |
| 1955 | static constexpr uint32_t PackNumMask{0x0000'01F0}; |
| 1956 | }; |
| 1957 | |
| 1958 | template <typename ValueType> struct PragmaStack { |
| 1959 | struct Slot { |
| 1960 | llvm::StringRef StackSlotLabel; |
| 1961 | ValueType Value; |
| 1962 | SourceLocation PragmaLocation; |
| 1963 | SourceLocation PragmaPushLocation; |
| 1964 | Slot(llvm::StringRef StackSlotLabel, ValueType Value, |
| 1965 | SourceLocation PragmaLocation, SourceLocation PragmaPushLocation) |
| 1966 | : StackSlotLabel(StackSlotLabel), Value(Value), |
| 1967 | PragmaLocation(PragmaLocation), |
| 1968 | PragmaPushLocation(PragmaPushLocation) {} |
| 1969 | }; |
| 1970 | |
| 1971 | void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, |
| 1972 | llvm::StringRef StackSlotLabel, ValueType Value) { |
| 1973 | if (Action == PSK_Reset) { |
| 1974 | CurrentValue = DefaultValue; |
| 1975 | CurrentPragmaLocation = PragmaLocation; |
| 1976 | return; |
| 1977 | } |
| 1978 | if (Action & PSK_Push) |
| 1979 | Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation, |
| 1980 | PragmaLocation); |
| 1981 | else if (Action & PSK_Pop) { |
| 1982 | if (!StackSlotLabel.empty()) { |
| 1983 | // If we've got a label, try to find it and jump there. |
| 1984 | auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) { |
| 1985 | return x.StackSlotLabel == StackSlotLabel; |
| 1986 | }); |
| 1987 | // If we found the label so pop from there. |
| 1988 | if (I != Stack.rend()) { |
| 1989 | CurrentValue = I->Value; |
| 1990 | CurrentPragmaLocation = I->PragmaLocation; |
| 1991 | Stack.erase(std::prev(I.base()), Stack.end()); |
| 1992 | } |
| 1993 | } else if (!Stack.empty()) { |
| 1994 | // We do not have a label, just pop the last entry. |
| 1995 | CurrentValue = Stack.back().Value; |
| 1996 | CurrentPragmaLocation = Stack.back().PragmaLocation; |
| 1997 | Stack.pop_back(); |
| 1998 | } |
| 1999 | } |
| 2000 | if (Action & PSK_Set) { |
| 2001 | CurrentValue = Value; |
| 2002 | CurrentPragmaLocation = PragmaLocation; |
| 2003 | } |
| 2004 | } |
| 2005 | |
| 2006 | // MSVC seems to add artificial slots to #pragma stacks on entering a C++ |
| 2007 | // method body to restore the stacks on exit, so it works like this: |
| 2008 | // |
| 2009 | // struct S { |
| 2010 | // #pragma <name>(push, InternalPragmaSlot, <current_pragma_value>) |
| 2011 | // void Method {} |
| 2012 | // #pragma <name>(pop, InternalPragmaSlot) |
| 2013 | // }; |
| 2014 | // |
| 2015 | // It works even with #pragma vtordisp, although MSVC doesn't support |
| 2016 | // #pragma vtordisp(push [, id], n) |
| 2017 | // syntax. |
| 2018 | // |
| 2019 | // Push / pop a named sentinel slot. |
| 2020 | void SentinelAction(PragmaMsStackAction Action, StringRef Label) { |
| 2021 | assert((Action == PSK_Push || Action == PSK_Pop) && |
| 2022 | "Can only push / pop #pragma stack sentinels!" ); |
| 2023 | Act(PragmaLocation: CurrentPragmaLocation, Action, StackSlotLabel: Label, Value: CurrentValue); |
| 2024 | } |
| 2025 | |
| 2026 | // Constructors. |
| 2027 | explicit PragmaStack(const ValueType &Default) |
| 2028 | : DefaultValue(Default), CurrentValue(Default) {} |
| 2029 | |
| 2030 | bool hasValue() const { return CurrentValue != DefaultValue; } |
| 2031 | |
| 2032 | SmallVector<Slot, 2> Stack; |
| 2033 | ValueType DefaultValue; // Value used for PSK_Reset action. |
| 2034 | ValueType CurrentValue; |
| 2035 | SourceLocation CurrentPragmaLocation; |
| 2036 | }; |
| 2037 | // FIXME: We should serialize / deserialize these if they occur in a PCH (but |
| 2038 | // we shouldn't do so if they're in a module). |
| 2039 | |
| 2040 | /// Whether to insert vtordisps prior to virtual bases in the Microsoft |
| 2041 | /// C++ ABI. Possible values are 0, 1, and 2, which mean: |
| 2042 | /// |
| 2043 | /// 0: Suppress all vtordisps |
| 2044 | /// 1: Insert vtordisps in the presence of vbase overrides and non-trivial |
| 2045 | /// structors |
| 2046 | /// 2: Always insert vtordisps to support RTTI on partially constructed |
| 2047 | /// objects |
| 2048 | PragmaStack<MSVtorDispMode> VtorDispStack; |
| 2049 | PragmaStack<AlignPackInfo> AlignPackStack; |
| 2050 | // The current #pragma align/pack values and locations at each #include. |
| 2051 | struct AlignPackIncludeState { |
| 2052 | AlignPackInfo CurrentValue; |
| 2053 | SourceLocation CurrentPragmaLocation; |
| 2054 | bool HasNonDefaultValue, ShouldWarnOnInclude; |
| 2055 | }; |
| 2056 | SmallVector<AlignPackIncludeState, 8> AlignPackIncludeStack; |
| 2057 | // Segment #pragmas. |
| 2058 | PragmaStack<StringLiteral *> DataSegStack; |
| 2059 | PragmaStack<StringLiteral *> BSSSegStack; |
| 2060 | PragmaStack<StringLiteral *> ConstSegStack; |
| 2061 | PragmaStack<StringLiteral *> CodeSegStack; |
| 2062 | |
| 2063 | // #pragma strict_gs_check. |
| 2064 | PragmaStack<bool> StrictGuardStackCheckStack; |
| 2065 | |
| 2066 | // This stack tracks the current state of Sema.CurFPFeatures. |
| 2067 | PragmaStack<FPOptionsOverride> FpPragmaStack; |
| 2068 | FPOptionsOverride CurFPFeatureOverrides() { |
| 2069 | FPOptionsOverride result; |
| 2070 | if (!FpPragmaStack.hasValue()) { |
| 2071 | result = FPOptionsOverride(); |
| 2072 | } else { |
| 2073 | result = FpPragmaStack.CurrentValue; |
| 2074 | } |
| 2075 | return result; |
| 2076 | } |
| 2077 | |
| 2078 | enum PragmaSectionKind { |
| 2079 | PSK_DataSeg, |
| 2080 | PSK_BSSSeg, |
| 2081 | PSK_ConstSeg, |
| 2082 | PSK_CodeSeg, |
| 2083 | }; |
| 2084 | |
| 2085 | // RAII object to push / pop sentinel slots for all MS #pragma stacks. |
| 2086 | // Actions should be performed only if we enter / exit a C++ method body. |
| 2087 | class PragmaStackSentinelRAII { |
| 2088 | public: |
| 2089 | PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct); |
| 2090 | ~PragmaStackSentinelRAII(); |
| 2091 | PragmaStackSentinelRAII(const PragmaStackSentinelRAII &) = delete; |
| 2092 | PragmaStackSentinelRAII & |
| 2093 | operator=(const PragmaStackSentinelRAII &) = delete; |
| 2094 | |
| 2095 | private: |
| 2096 | Sema &S; |
| 2097 | StringRef SlotLabel; |
| 2098 | bool ShouldAct; |
| 2099 | }; |
| 2100 | |
| 2101 | /// Last section used with #pragma init_seg. |
| 2102 | StringLiteral *CurInitSeg; |
| 2103 | SourceLocation CurInitSegLoc; |
| 2104 | |
| 2105 | /// Sections used with #pragma alloc_text. |
| 2106 | llvm::StringMap<std::tuple<StringRef, SourceLocation>> FunctionToSectionMap; |
| 2107 | |
| 2108 | /// VisContext - Manages the stack for \#pragma GCC visibility. |
| 2109 | void *VisContext; // Really a "PragmaVisStack*" |
| 2110 | |
| 2111 | /// This an attribute introduced by \#pragma clang attribute. |
| 2112 | struct PragmaAttributeEntry { |
| 2113 | SourceLocation Loc; |
| 2114 | ParsedAttr *Attribute; |
| 2115 | SmallVector<attr::SubjectMatchRule, 4> MatchRules; |
| 2116 | bool IsUsed; |
| 2117 | }; |
| 2118 | |
| 2119 | /// A push'd group of PragmaAttributeEntries. |
| 2120 | struct PragmaAttributeGroup { |
| 2121 | /// The location of the push attribute. |
| 2122 | SourceLocation Loc; |
| 2123 | /// The namespace of this push group. |
| 2124 | const IdentifierInfo *Namespace; |
| 2125 | SmallVector<PragmaAttributeEntry, 2> Entries; |
| 2126 | }; |
| 2127 | |
| 2128 | SmallVector<PragmaAttributeGroup, 2> PragmaAttributeStack; |
| 2129 | |
| 2130 | /// The declaration that is currently receiving an attribute from the |
| 2131 | /// #pragma attribute stack. |
| 2132 | const Decl *PragmaAttributeCurrentTargetDecl; |
| 2133 | |
| 2134 | /// This represents the last location of a "#pragma clang optimize off" |
| 2135 | /// directive if such a directive has not been closed by an "on" yet. If |
| 2136 | /// optimizations are currently "on", this is set to an invalid location. |
| 2137 | SourceLocation OptimizeOffPragmaLocation; |
| 2138 | |
| 2139 | /// Get the location for the currently active "\#pragma clang optimize |
| 2140 | /// off". If this location is invalid, then the state of the pragma is "on". |
| 2141 | SourceLocation getOptimizeOffPragmaLocation() const { |
| 2142 | return OptimizeOffPragmaLocation; |
| 2143 | } |
| 2144 | |
| 2145 | /// The "on" or "off" argument passed by \#pragma optimize, that denotes |
| 2146 | /// whether the optimizations in the list passed to the pragma should be |
| 2147 | /// turned off or on. This boolean is true by default because command line |
| 2148 | /// options are honored when `#pragma optimize("", on)`. |
| 2149 | /// (i.e. `ModifyFnAttributeMSPragmaOptimze()` does nothing) |
| 2150 | bool MSPragmaOptimizeIsOn = true; |
| 2151 | |
| 2152 | /// Set of no-builtin functions listed by \#pragma function. |
| 2153 | llvm::SmallSetVector<StringRef, 4> MSFunctionNoBuiltins; |
| 2154 | |
| 2155 | /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to |
| 2156 | /// a the record decl, to handle '\#pragma pack' and '\#pragma options align'. |
| 2157 | void AddAlignmentAttributesForRecord(RecordDecl *RD); |
| 2158 | |
| 2159 | /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record. |
| 2160 | void AddMsStructLayoutForRecord(RecordDecl *RD); |
| 2161 | |
| 2162 | /// Add gsl::Pointer attribute to std::container::iterator |
| 2163 | /// \param ND The declaration that introduces the name |
| 2164 | /// std::container::iterator. \param UnderlyingRecord The record named by ND. |
| 2165 | void inferGslPointerAttribute(NamedDecl *ND, CXXRecordDecl *UnderlyingRecord); |
| 2166 | |
| 2167 | /// Add [[gsl::Owner]] and [[gsl::Pointer]] attributes for std:: types. |
| 2168 | void inferGslOwnerPointerAttribute(CXXRecordDecl *Record); |
| 2169 | |
| 2170 | /// Add [[clang:::lifetimebound]] attr for std:: functions and methods. |
| 2171 | void inferLifetimeBoundAttribute(FunctionDecl *FD); |
| 2172 | |
| 2173 | /// Add [[clang:::lifetime_capture_by(this)]] to STL container methods. |
| 2174 | void inferLifetimeCaptureByAttribute(FunctionDecl *FD); |
| 2175 | |
| 2176 | /// Add [[gsl::Pointer]] attributes for std:: types. |
| 2177 | void inferGslPointerAttribute(TypedefNameDecl *TD); |
| 2178 | |
| 2179 | LifetimeCaptureByAttr *ParseLifetimeCaptureByAttr(const ParsedAttr &AL, |
| 2180 | StringRef ParamName); |
| 2181 | // Processes the argument 'X' in [[clang::lifetime_capture_by(X)]]. Since 'X' |
| 2182 | // can be the name of a function parameter, we need to parse the function |
| 2183 | // declaration and rest of the parameters before processesing 'X'. Therefore |
| 2184 | // do this lazily instead of processing while parsing the annotation itself. |
| 2185 | void LazyProcessLifetimeCaptureByParams(FunctionDecl *FD); |
| 2186 | |
| 2187 | /// Add _Nullable attributes for std:: types. |
| 2188 | void inferNullableClassAttribute(CXXRecordDecl *CRD); |
| 2189 | |
| 2190 | /// ActOnPragmaClangSection - Called on well formed \#pragma clang section |
| 2191 | void ActOnPragmaClangSection(SourceLocation PragmaLoc, |
| 2192 | PragmaClangSectionAction Action, |
| 2193 | PragmaClangSectionKind SecKind, |
| 2194 | StringRef SecName); |
| 2195 | |
| 2196 | /// ActOnPragmaOptionsAlign - Called on well formed \#pragma options align. |
| 2197 | void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, |
| 2198 | SourceLocation PragmaLoc); |
| 2199 | |
| 2200 | /// ActOnPragmaPack - Called on well formed \#pragma pack(...). |
| 2201 | void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, |
| 2202 | StringRef SlotLabel, Expr *Alignment); |
| 2203 | |
| 2204 | /// ConstantFoldAttrArgs - Folds attribute arguments into ConstantExprs |
| 2205 | /// (unless they are value dependent or type dependent). Returns false |
| 2206 | /// and emits a diagnostic if one or more of the arguments could not be |
| 2207 | /// folded into a constant. |
| 2208 | bool ConstantFoldAttrArgs(const AttributeCommonInfo &CI, |
| 2209 | MutableArrayRef<Expr *> Args); |
| 2210 | |
| 2211 | enum class PragmaAlignPackDiagnoseKind { |
| 2212 | NonDefaultStateAtInclude, |
| 2213 | ChangedStateAtExit |
| 2214 | }; |
| 2215 | |
| 2216 | void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind, |
| 2217 | SourceLocation IncludeLoc); |
| 2218 | void DiagnoseUnterminatedPragmaAlignPack(); |
| 2219 | |
| 2220 | /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off]. |
| 2221 | void ActOnPragmaMSStruct(PragmaMSStructKind Kind); |
| 2222 | |
| 2223 | /// ActOnPragmaMSComment - Called on well formed |
| 2224 | /// \#pragma comment(kind, "arg"). |
| 2225 | void (SourceLocation , PragmaMSCommentKind Kind, |
| 2226 | StringRef Arg); |
| 2227 | |
| 2228 | /// ActOnPragmaDetectMismatch - Call on well-formed \#pragma detect_mismatch |
| 2229 | void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, |
| 2230 | StringRef Value); |
| 2231 | |
| 2232 | /// Are precise floating point semantics currently enabled? |
| 2233 | bool isPreciseFPEnabled() { |
| 2234 | return !CurFPFeatures.getAllowFPReassociate() && |
| 2235 | !CurFPFeatures.getNoSignedZero() && |
| 2236 | !CurFPFeatures.getAllowReciprocal() && |
| 2237 | !CurFPFeatures.getAllowApproxFunc(); |
| 2238 | } |
| 2239 | |
| 2240 | void ActOnPragmaFPEvalMethod(SourceLocation Loc, |
| 2241 | LangOptions::FPEvalMethodKind Value); |
| 2242 | |
| 2243 | /// ActOnPragmaFloatControl - Call on well-formed \#pragma float_control |
| 2244 | void ActOnPragmaFloatControl(SourceLocation Loc, PragmaMsStackAction Action, |
| 2245 | PragmaFloatControlKind Value); |
| 2246 | |
| 2247 | /// ActOnPragmaMSPointersToMembers - called on well formed \#pragma |
| 2248 | /// pointers_to_members(representation method[, general purpose |
| 2249 | /// representation]). |
| 2250 | void ActOnPragmaMSPointersToMembers( |
| 2251 | LangOptions::PragmaMSPointersToMembersKind Kind, |
| 2252 | SourceLocation PragmaLoc); |
| 2253 | |
| 2254 | /// Called on well formed \#pragma vtordisp(). |
| 2255 | void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, |
| 2256 | SourceLocation PragmaLoc, MSVtorDispMode Value); |
| 2257 | |
| 2258 | bool UnifySection(StringRef SectionName, int SectionFlags, |
| 2259 | NamedDecl *TheDecl); |
| 2260 | bool UnifySection(StringRef SectionName, int SectionFlags, |
| 2261 | SourceLocation PragmaSectionLocation); |
| 2262 | |
| 2263 | /// Called on well formed \#pragma bss_seg/data_seg/const_seg/code_seg. |
| 2264 | void ActOnPragmaMSSeg(SourceLocation PragmaLocation, |
| 2265 | PragmaMsStackAction Action, |
| 2266 | llvm::StringRef StackSlotLabel, |
| 2267 | StringLiteral *SegmentName, llvm::StringRef PragmaName); |
| 2268 | |
| 2269 | /// Called on well formed \#pragma section(). |
| 2270 | void ActOnPragmaMSSection(SourceLocation PragmaLocation, int SectionFlags, |
| 2271 | StringLiteral *SegmentName); |
| 2272 | |
| 2273 | /// Called on well-formed \#pragma init_seg(). |
| 2274 | void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, |
| 2275 | StringLiteral *SegmentName); |
| 2276 | |
| 2277 | /// Called on well-formed \#pragma alloc_text(). |
| 2278 | void ActOnPragmaMSAllocText( |
| 2279 | SourceLocation PragmaLocation, StringRef Section, |
| 2280 | const SmallVector<std::tuple<IdentifierInfo *, SourceLocation>> |
| 2281 | &Functions); |
| 2282 | |
| 2283 | /// ActOnPragmaMSStrictGuardStackCheck - Called on well formed \#pragma |
| 2284 | /// strict_gs_check. |
| 2285 | void ActOnPragmaMSStrictGuardStackCheck(SourceLocation PragmaLocation, |
| 2286 | PragmaMsStackAction Action, |
| 2287 | bool Value); |
| 2288 | |
| 2289 | /// ActOnPragmaUnused - Called on well-formed '\#pragma unused'. |
| 2290 | void ActOnPragmaUnused(const Token &Identifier, Scope *curScope, |
| 2291 | SourceLocation PragmaLoc); |
| 2292 | |
| 2293 | void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute, |
| 2294 | SourceLocation PragmaLoc, |
| 2295 | attr::ParsedSubjectMatchRuleSet Rules); |
| 2296 | void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, |
| 2297 | const IdentifierInfo *Namespace); |
| 2298 | |
| 2299 | /// Called on well-formed '\#pragma clang attribute pop'. |
| 2300 | void ActOnPragmaAttributePop(SourceLocation PragmaLoc, |
| 2301 | const IdentifierInfo *Namespace); |
| 2302 | |
| 2303 | /// Adds the attributes that have been specified using the |
| 2304 | /// '\#pragma clang attribute push' directives to the given declaration. |
| 2305 | void AddPragmaAttributes(Scope *S, Decl *D); |
| 2306 | |
| 2307 | using InstantiationContextDiagFuncRef = |
| 2308 | llvm::function_ref<void(SourceLocation, PartialDiagnostic)>; |
| 2309 | auto getDefaultDiagFunc() { |
| 2310 | return [this](SourceLocation Loc, PartialDiagnostic PD) { |
| 2311 | // This bypasses a lot of the filters in the diag engine, as it's |
| 2312 | // to be used to attach notes to diagnostics which have already |
| 2313 | // been filtered through. |
| 2314 | DiagnosticBuilder Builder(Diags.Report(Loc, DiagID: PD.getDiagID())); |
| 2315 | PD.Emit(DB: Builder); |
| 2316 | }; |
| 2317 | } |
| 2318 | |
| 2319 | void PrintPragmaAttributeInstantiationPoint( |
| 2320 | InstantiationContextDiagFuncRef DiagFunc); |
| 2321 | void PrintPragmaAttributeInstantiationPoint() { |
| 2322 | PrintPragmaAttributeInstantiationPoint(DiagFunc: getDefaultDiagFunc()); |
| 2323 | } |
| 2324 | |
| 2325 | void DiagnoseUnterminatedPragmaAttribute(); |
| 2326 | |
| 2327 | /// Called on well formed \#pragma clang optimize. |
| 2328 | void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc); |
| 2329 | |
| 2330 | /// #pragma optimize("[optimization-list]", on | off). |
| 2331 | void ActOnPragmaMSOptimize(SourceLocation Loc, bool IsOn); |
| 2332 | |
| 2333 | /// Call on well formed \#pragma function. |
| 2334 | void |
| 2335 | ActOnPragmaMSFunction(SourceLocation Loc, |
| 2336 | const llvm::SmallVectorImpl<StringRef> &NoBuiltins); |
| 2337 | |
| 2338 | NamedDecl *lookupExternCFunctionOrVariable(IdentifierInfo *IdentId, |
| 2339 | SourceLocation NameLoc, |
| 2340 | Scope *curScope); |
| 2341 | |
| 2342 | /// Information from a C++ #pragma export, for a symbol that we |
| 2343 | /// haven't seen the declaration for yet. |
| 2344 | struct PendingPragmaInfo { |
| 2345 | SourceLocation NameLoc; |
| 2346 | bool Used; |
| 2347 | }; |
| 2348 | |
| 2349 | llvm::DenseMap<IdentifierInfo *, PendingPragmaInfo> PendingExportedNames; |
| 2350 | |
| 2351 | /// ActonPragmaExport - called on well-formed '\#pragma export'. |
| 2352 | void ActOnPragmaExport(IdentifierInfo *IdentId, SourceLocation ExportNameLoc, |
| 2353 | Scope *curScope); |
| 2354 | |
| 2355 | /// Only called on function definitions; if there is a pragma in scope |
| 2356 | /// with the effect of a range-based optnone, consider marking the function |
| 2357 | /// with attribute optnone. |
| 2358 | void AddRangeBasedOptnone(FunctionDecl *FD); |
| 2359 | |
| 2360 | /// Only called on function definitions; if there is a `#pragma alloc_text` |
| 2361 | /// that decides which code section the function should be in, add |
| 2362 | /// attribute section to the function. |
| 2363 | void AddSectionMSAllocText(FunctionDecl *FD); |
| 2364 | |
| 2365 | /// Adds the 'optnone' attribute to the function declaration if there |
| 2366 | /// are no conflicts; Loc represents the location causing the 'optnone' |
| 2367 | /// attribute to be added (usually because of a pragma). |
| 2368 | void AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD, SourceLocation Loc); |
| 2369 | |
| 2370 | /// Only called on function definitions; if there is a MSVC #pragma optimize |
| 2371 | /// in scope, consider changing the function's attributes based on the |
| 2372 | /// optimization list passed to the pragma. |
| 2373 | void ModifyFnAttributesMSPragmaOptimize(FunctionDecl *FD); |
| 2374 | |
| 2375 | /// Only called on function definitions; if there is a pragma in scope |
| 2376 | /// with the effect of a range-based no_builtin, consider marking the function |
| 2377 | /// with attribute no_builtin. |
| 2378 | void AddImplicitMSFunctionNoBuiltinAttr(FunctionDecl *FD); |
| 2379 | |
| 2380 | /// AddPushedVisibilityAttribute - If '\#pragma GCC visibility' was used, |
| 2381 | /// add an appropriate visibility attribute. |
| 2382 | void AddPushedVisibilityAttribute(Decl *RD); |
| 2383 | |
| 2384 | /// FreeVisContext - Deallocate and null out VisContext. |
| 2385 | void FreeVisContext(); |
| 2386 | |
| 2387 | /// ActOnPragmaVisibility - Called on well formed \#pragma GCC visibility... . |
| 2388 | void ActOnPragmaVisibility(const IdentifierInfo *VisType, |
| 2389 | SourceLocation PragmaLoc); |
| 2390 | |
| 2391 | /// ActOnPragmaFPContract - Called on well formed |
| 2392 | /// \#pragma {STDC,OPENCL} FP_CONTRACT and |
| 2393 | /// \#pragma clang fp contract |
| 2394 | void ActOnPragmaFPContract(SourceLocation Loc, LangOptions::FPModeKind FPC); |
| 2395 | |
| 2396 | /// Called on well formed |
| 2397 | /// \#pragma clang fp reassociate |
| 2398 | /// or |
| 2399 | /// \#pragma clang fp reciprocal |
| 2400 | void ActOnPragmaFPValueChangingOption(SourceLocation Loc, PragmaFPKind Kind, |
| 2401 | bool IsEnabled); |
| 2402 | |
| 2403 | /// ActOnPragmaFenvAccess - Called on well formed |
| 2404 | /// \#pragma STDC FENV_ACCESS |
| 2405 | void ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled); |
| 2406 | |
| 2407 | /// ActOnPragmaCXLimitedRange - Called on well formed |
| 2408 | /// \#pragma STDC CX_LIMITED_RANGE |
| 2409 | void ActOnPragmaCXLimitedRange(SourceLocation Loc, |
| 2410 | LangOptions::ComplexRangeKind Range); |
| 2411 | |
| 2412 | /// Called on well formed '\#pragma clang fp' that has option 'exceptions'. |
| 2413 | void ActOnPragmaFPExceptions(SourceLocation Loc, |
| 2414 | LangOptions::FPExceptionModeKind); |
| 2415 | |
| 2416 | /// Called to set constant rounding mode for floating point operations. |
| 2417 | void ActOnPragmaFEnvRound(SourceLocation Loc, llvm::RoundingMode); |
| 2418 | |
| 2419 | /// Called to set exception behavior for floating point operations. |
| 2420 | void setExceptionMode(SourceLocation Loc, LangOptions::FPExceptionModeKind); |
| 2421 | |
| 2422 | /// PushNamespaceVisibilityAttr - Note that we've entered a |
| 2423 | /// namespace with a visibility attribute. |
| 2424 | void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, |
| 2425 | SourceLocation Loc); |
| 2426 | |
| 2427 | /// PopPragmaVisibility - Pop the top element of the visibility stack; used |
| 2428 | /// for '\#pragma GCC visibility' and visibility attributes on namespaces. |
| 2429 | void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc); |
| 2430 | |
| 2431 | /// Handles semantic checking for features that are common to all attributes, |
| 2432 | /// such as checking whether a parameter was properly specified, or the |
| 2433 | /// correct number of arguments were passed, etc. Returns true if the |
| 2434 | /// attribute has been diagnosed. |
| 2435 | bool checkCommonAttributeFeatures(const Decl *D, const ParsedAttr &A, |
| 2436 | bool SkipArgCountCheck = false); |
| 2437 | bool checkCommonAttributeFeatures(const Stmt *S, const ParsedAttr &A, |
| 2438 | bool SkipArgCountCheck = false); |
| 2439 | |
| 2440 | ///@} |
| 2441 | |
| 2442 | // |
| 2443 | // |
| 2444 | // ------------------------------------------------------------------------- |
| 2445 | // |
| 2446 | // |
| 2447 | |
| 2448 | /// \name Availability Attribute Handling |
| 2449 | /// Implementations are in SemaAvailability.cpp |
| 2450 | ///@{ |
| 2451 | |
| 2452 | public: |
| 2453 | /// Issue any -Wunguarded-availability warnings in \c FD |
| 2454 | void DiagnoseUnguardedAvailabilityViolations(Decl *FD); |
| 2455 | |
| 2456 | void handleDelayedAvailabilityCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); |
| 2457 | |
| 2458 | /// Retrieve the current function, if any, that should be analyzed for |
| 2459 | /// potential availability violations. |
| 2460 | sema::FunctionScopeInfo *getCurFunctionAvailabilityContext(); |
| 2461 | |
| 2462 | void DiagnoseAvailabilityOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, |
| 2463 | const ObjCInterfaceDecl *UnknownObjCClass, |
| 2464 | bool ObjCPropertyAccess, |
| 2465 | bool AvoidPartialAvailabilityChecks, |
| 2466 | ObjCInterfaceDecl *ClassReceiver); |
| 2467 | |
| 2468 | void DiagnoseAvailabilityOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs); |
| 2469 | |
| 2470 | std::pair<AvailabilityResult, const NamedDecl *> |
| 2471 | ShouldDiagnoseAvailabilityOfDecl(const NamedDecl *D, std::string *Message, |
| 2472 | ObjCInterfaceDecl *ClassReceiver); |
| 2473 | ///@} |
| 2474 | |
| 2475 | // |
| 2476 | // |
| 2477 | // ------------------------------------------------------------------------- |
| 2478 | // |
| 2479 | // |
| 2480 | |
| 2481 | /// \name Bounds Safety |
| 2482 | /// Implementations are in SemaBoundsSafety.cpp |
| 2483 | ///@{ |
| 2484 | public: |
| 2485 | /// Check if applying the specified attribute variant from the "counted by" |
| 2486 | /// family of attributes to FieldDecl \p FD is semantically valid. If |
| 2487 | /// semantically invalid diagnostics will be emitted explaining the problems. |
| 2488 | /// |
| 2489 | /// \param FD The FieldDecl to apply the attribute to |
| 2490 | /// \param E The count expression on the attribute |
| 2491 | /// \param CountInBytes If true the attribute is from the "sized_by" family of |
| 2492 | /// attributes. If the false the attribute is from |
| 2493 | /// "counted_by" family of attributes. |
| 2494 | /// \param OrNull If true the attribute is from the "_or_null" suffixed family |
| 2495 | /// of attributes. If false the attribute does not have the |
| 2496 | /// suffix. |
| 2497 | /// |
| 2498 | /// Together \p CountInBytes and \p OrNull decide the attribute variant. E.g. |
| 2499 | /// \p CountInBytes and \p OrNull both being true indicates the |
| 2500 | /// `counted_by_or_null` attribute. |
| 2501 | /// |
| 2502 | /// \returns false iff semantically valid. |
| 2503 | bool CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, |
| 2504 | bool OrNull); |
| 2505 | |
| 2506 | /// Perform Bounds Safety Semantic checks for assigning to a `__counted_by` or |
| 2507 | /// `__counted_by_or_null` pointer type \param LHSTy. |
| 2508 | /// |
| 2509 | /// \param LHSTy The type being assigned to. Checks will only be performed if |
| 2510 | /// the type is a `counted_by` or `counted_by_or_null ` pointer. |
| 2511 | /// \param RHSExpr The expression being assigned from. |
| 2512 | /// \param Action The type assignment being performed |
| 2513 | /// \param Loc The SourceLocation to use for error diagnostics |
| 2514 | /// \param Assignee The ValueDecl being assigned. This is used to compute |
| 2515 | /// the name of the assignee. If the assignee isn't known this can |
| 2516 | /// be set to nullptr. |
| 2517 | /// \param ShowFullyQualifiedAssigneeName If set to true when using \p |
| 2518 | /// Assignee to compute the name of the assignee use the fully |
| 2519 | /// qualified name, otherwise use the unqualified name. |
| 2520 | /// |
| 2521 | /// \returns True iff no diagnostic where emitted, false otherwise. |
| 2522 | bool BoundsSafetyCheckAssignmentToCountAttrPtr( |
| 2523 | QualType LHSTy, Expr *RHSExpr, AssignmentAction Action, |
| 2524 | SourceLocation Loc, const ValueDecl *Assignee, |
| 2525 | bool ShowFullyQualifiedAssigneeName); |
| 2526 | |
| 2527 | /// Perform Bounds Safety Semantic checks for initializing a Bounds Safety |
| 2528 | /// pointer. |
| 2529 | /// |
| 2530 | /// \param Entity The entity being initialized |
| 2531 | /// \param Kind The kind of initialization being performed |
| 2532 | /// \param Action The type assignment being performed |
| 2533 | /// \param LHSTy The type being assigned to. Checks will only be performed if |
| 2534 | /// the type is a `counted_by` or `counted_by_or_null ` pointer. |
| 2535 | /// \param RHSExpr The expression being used for initialization. |
| 2536 | /// |
| 2537 | /// \returns True iff no diagnostic where emitted, false otherwise. |
| 2538 | bool BoundsSafetyCheckInitialization(const InitializedEntity &Entity, |
| 2539 | const InitializationKind &Kind, |
| 2540 | AssignmentAction Action, |
| 2541 | QualType LHSType, Expr *RHSExpr); |
| 2542 | |
| 2543 | /// Perform Bounds Safety semantic checks for uses of invalid uses counted_by |
| 2544 | /// or counted_by_or_null pointers in \param E. |
| 2545 | /// |
| 2546 | /// \param E the expression to check |
| 2547 | /// |
| 2548 | /// \returns True iff no diagnostic where emitted, false otherwise. |
| 2549 | bool BoundsSafetyCheckUseOfCountAttrPtr(const Expr *E); |
| 2550 | ///@} |
| 2551 | |
| 2552 | // |
| 2553 | // |
| 2554 | // ------------------------------------------------------------------------- |
| 2555 | // |
| 2556 | // |
| 2557 | |
| 2558 | /// \name Casts |
| 2559 | /// Implementations are in SemaCast.cpp |
| 2560 | ///@{ |
| 2561 | |
| 2562 | public: |
| 2563 | static bool isCast(CheckedConversionKind CCK) { |
| 2564 | return CCK == CheckedConversionKind::CStyleCast || |
| 2565 | CCK == CheckedConversionKind::FunctionalCast || |
| 2566 | CCK == CheckedConversionKind::OtherCast; |
| 2567 | } |
| 2568 | |
| 2569 | /// ActOnCXXNamedCast - Parse |
| 2570 | /// {dynamic,static,reinterpret,const,addrspace}_cast's. |
| 2571 | ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, |
| 2572 | SourceLocation LAngleBracketLoc, Declarator &D, |
| 2573 | SourceLocation RAngleBracketLoc, |
| 2574 | SourceLocation LParenLoc, Expr *E, |
| 2575 | SourceLocation RParenLoc); |
| 2576 | |
| 2577 | ExprResult BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, |
| 2578 | TypeSourceInfo *Ty, Expr *E, |
| 2579 | SourceRange AngleBrackets, SourceRange Parens); |
| 2580 | |
| 2581 | ExprResult ActOnBuiltinBitCastExpr(SourceLocation KWLoc, Declarator &Dcl, |
| 2582 | ExprResult Operand, |
| 2583 | SourceLocation RParenLoc); |
| 2584 | |
| 2585 | ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, |
| 2586 | Expr *Operand, SourceLocation RParenLoc); |
| 2587 | |
| 2588 | // Checks that reinterpret casts don't have undefined behavior. |
| 2589 | void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, |
| 2590 | bool IsDereference, SourceRange Range); |
| 2591 | |
| 2592 | // Checks that the vector type should be initialized from a scalar |
| 2593 | // by splatting the value rather than populating a single element. |
| 2594 | // This is the case for AltiVecVector types as well as with |
| 2595 | // AltiVecPixel and AltiVecBool when -faltivec-src-compat=xl is specified. |
| 2596 | bool ShouldSplatAltivecScalarInCast(const VectorType *VecTy); |
| 2597 | |
| 2598 | // Checks if the -faltivec-src-compat=gcc option is specified. |
| 2599 | // If so, AltiVecVector, AltiVecBool and AltiVecPixel types are |
| 2600 | // treated the same way as they are when trying to initialize |
| 2601 | // these vectors on gcc (an error is emitted). |
| 2602 | bool CheckAltivecInitFromScalar(SourceRange R, QualType VecTy, |
| 2603 | QualType SrcTy); |
| 2604 | |
| 2605 | ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *Ty, |
| 2606 | SourceLocation RParenLoc, Expr *Op); |
| 2607 | |
| 2608 | ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, QualType Type, |
| 2609 | SourceLocation LParenLoc, |
| 2610 | Expr *CastExpr, |
| 2611 | SourceLocation RParenLoc); |
| 2612 | |
| 2613 | ///@} |
| 2614 | |
| 2615 | // |
| 2616 | // |
| 2617 | // ------------------------------------------------------------------------- |
| 2618 | // |
| 2619 | // |
| 2620 | |
| 2621 | /// \name Extra Semantic Checking |
| 2622 | /// Implementations are in SemaChecking.cpp |
| 2623 | ///@{ |
| 2624 | |
| 2625 | public: |
| 2626 | /// Used to change context to isConstantEvaluated without pushing a heavy |
| 2627 | /// ExpressionEvaluationContextRecord object. |
| 2628 | bool isConstantEvaluatedOverride = false; |
| 2629 | |
| 2630 | bool isConstantEvaluatedContext() const { |
| 2631 | return currentEvaluationContext().isConstantEvaluated() || |
| 2632 | isConstantEvaluatedOverride; |
| 2633 | } |
| 2634 | |
| 2635 | SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, |
| 2636 | unsigned ByteNo) const; |
| 2637 | |
| 2638 | enum FormatArgumentPassingKind { |
| 2639 | FAPK_Fixed, // values to format are fixed (no C-style variadic arguments) |
| 2640 | FAPK_Variadic, // values to format are passed as variadic arguments |
| 2641 | FAPK_VAList, // values to format are passed in a va_list |
| 2642 | FAPK_Elsewhere, // values to format are not passed to this function |
| 2643 | }; |
| 2644 | |
| 2645 | // Used to grab the relevant information from a FormatAttr and a |
| 2646 | // FunctionDeclaration. |
| 2647 | struct FormatStringInfo { |
| 2648 | unsigned FormatIdx; |
| 2649 | unsigned FirstDataArg; |
| 2650 | FormatArgumentPassingKind ArgPassingKind; |
| 2651 | }; |
| 2652 | |
| 2653 | /// Given a function and its FormatAttr or FormatMatchesAttr info, attempts to |
| 2654 | /// populate the FormatStringInfo parameter with the attribute's correct |
| 2655 | /// format_idx and firstDataArg. Returns true when the format fits the |
| 2656 | /// function and the FormatStringInfo has been populated. |
| 2657 | static bool getFormatStringInfo(const Decl *Function, unsigned FormatIdx, |
| 2658 | unsigned FirstArg, FormatStringInfo *FSI); |
| 2659 | static bool getFormatStringInfo(unsigned FormatIdx, unsigned FirstArg, |
| 2660 | bool HasImplicitThisParam, bool IsVariadic, |
| 2661 | FormatStringInfo *FSI); |
| 2662 | |
| 2663 | // Used by C++ template instantiation. |
| 2664 | ExprResult BuiltinShuffleVector(CallExpr *TheCall); |
| 2665 | |
| 2666 | /// ConvertVectorExpr - Handle __builtin_convertvector |
| 2667 | ExprResult ConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo, |
| 2668 | SourceLocation BuiltinLoc, |
| 2669 | SourceLocation RParenLoc); |
| 2670 | |
| 2671 | static StringRef GetFormatStringTypeName(FormatStringType FST); |
| 2672 | static FormatStringType GetFormatStringType(StringRef FormatFlavor); |
| 2673 | static FormatStringType GetFormatStringType(const FormatAttr *Format); |
| 2674 | static FormatStringType GetFormatStringType(const FormatMatchesAttr *Format); |
| 2675 | |
| 2676 | bool FormatStringHasSArg(const StringLiteral *FExpr); |
| 2677 | |
| 2678 | /// Check for comparisons of floating-point values using == and !=. Issue a |
| 2679 | /// warning if the comparison is not likely to do what the programmer |
| 2680 | /// intended. |
| 2681 | void CheckFloatComparison(SourceLocation Loc, const Expr *LHS, |
| 2682 | const Expr *RHS, BinaryOperatorKind Opcode); |
| 2683 | |
| 2684 | /// Register a magic integral constant to be used as a type tag. |
| 2685 | void RegisterTypeTagForDatatype(const IdentifierInfo *ArgumentKind, |
| 2686 | uint64_t MagicValue, QualType Type, |
| 2687 | bool LayoutCompatible, bool MustBeNull); |
| 2688 | |
| 2689 | struct TypeTagData { |
| 2690 | TypeTagData() {} |
| 2691 | |
| 2692 | TypeTagData(QualType Type, bool LayoutCompatible, bool MustBeNull) |
| 2693 | : Type(Type), LayoutCompatible(LayoutCompatible), |
| 2694 | MustBeNull(MustBeNull) {} |
| 2695 | |
| 2696 | QualType Type; |
| 2697 | |
| 2698 | /// If true, \c Type should be compared with other expression's types for |
| 2699 | /// layout-compatibility. |
| 2700 | LLVM_PREFERRED_TYPE(bool) |
| 2701 | unsigned LayoutCompatible : 1; |
| 2702 | LLVM_PREFERRED_TYPE(bool) |
| 2703 | unsigned MustBeNull : 1; |
| 2704 | }; |
| 2705 | |
| 2706 | /// A pair of ArgumentKind identifier and magic value. This uniquely |
| 2707 | /// identifies the magic value. |
| 2708 | typedef std::pair<const IdentifierInfo *, uint64_t> TypeTagMagicValue; |
| 2709 | |
| 2710 | /// Diagnoses the current set of gathered accesses. This happens at the end of |
| 2711 | /// each expression evaluation context. Diagnostics are emitted only for |
| 2712 | /// accesses gathered in the current evaluation context. |
| 2713 | void DiagnoseMisalignedMembers(); |
| 2714 | |
| 2715 | /// This function checks if the expression is in the sef of potentially |
| 2716 | /// misaligned members and it is converted to some pointer type T with lower |
| 2717 | /// or equal alignment requirements. If so it removes it. This is used when |
| 2718 | /// we do not want to diagnose such misaligned access (e.g. in conversions to |
| 2719 | /// void*). |
| 2720 | void DiscardMisalignedMemberAddress(const Type *T, Expr *E); |
| 2721 | |
| 2722 | /// Returns true if `From` is a function or pointer to a function with the |
| 2723 | /// `cfi_unchecked_callee` attribute but `To` is a function or pointer to |
| 2724 | /// function without this attribute. |
| 2725 | bool DiscardingCFIUncheckedCallee(QualType From, QualType To) const; |
| 2726 | |
| 2727 | /// This function calls Action when it determines that E designates a |
| 2728 | /// misaligned member due to the packed attribute. This is used to emit |
| 2729 | /// local diagnostics like in reference binding. |
| 2730 | void RefersToMemberWithReducedAlignment( |
| 2731 | Expr *E, |
| 2732 | llvm::function_ref<void(Expr *, RecordDecl *, FieldDecl *, CharUnits)> |
| 2733 | Action); |
| 2734 | |
| 2735 | enum class AtomicArgumentOrder { API, AST }; |
| 2736 | ExprResult |
| 2737 | BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange, |
| 2738 | SourceLocation RParenLoc, MultiExprArg Args, |
| 2739 | AtomicExpr::AtomicOp Op, |
| 2740 | AtomicArgumentOrder ArgOrder = AtomicArgumentOrder::API); |
| 2741 | |
| 2742 | /// Check to see if a given expression could have '.c_str()' called on it. |
| 2743 | bool hasCStrMethod(const Expr *E); |
| 2744 | |
| 2745 | /// Diagnose pointers that are always non-null. |
| 2746 | /// \param E the expression containing the pointer |
| 2747 | /// \param NullKind NPCK_NotNull if E is a cast to bool, otherwise, E is |
| 2748 | /// compared to a null pointer |
| 2749 | /// \param IsEqual True when the comparison is equal to a null pointer |
| 2750 | /// \param Range Extra SourceRange to highlight in the diagnostic |
| 2751 | void DiagnoseAlwaysNonNullPointer(Expr *E, |
| 2752 | Expr::NullPointerConstantKind NullType, |
| 2753 | bool IsEqual, SourceRange Range); |
| 2754 | |
| 2755 | /// CheckParmsForFunctionDef - Check that the parameters of the given |
| 2756 | /// function are appropriate for the definition of a function. This |
| 2757 | /// takes care of any checks that cannot be performed on the |
| 2758 | /// declaration itself, e.g., that the types of each of the function |
| 2759 | /// parameters are complete. |
| 2760 | bool CheckParmsForFunctionDef(ArrayRef<ParmVarDecl *> Parameters, |
| 2761 | bool CheckParameterNames); |
| 2762 | |
| 2763 | /// CheckCastAlign - Implements -Wcast-align, which warns when a |
| 2764 | /// pointer cast increases the alignment requirements. |
| 2765 | void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange); |
| 2766 | |
| 2767 | /// checkUnsafeAssigns - Check whether +1 expr is being assigned |
| 2768 | /// to weak/__unsafe_unretained type. |
| 2769 | bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS); |
| 2770 | |
| 2771 | /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned |
| 2772 | /// to weak/__unsafe_unretained expression. |
| 2773 | void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS); |
| 2774 | |
| 2775 | /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null |
| 2776 | /// statement as a \p Body, and it is located on the same line. |
| 2777 | /// |
| 2778 | /// This helps prevent bugs due to typos, such as: |
| 2779 | /// if (condition); |
| 2780 | /// do_stuff(); |
| 2781 | void DiagnoseEmptyStmtBody(SourceLocation StmtLoc, const Stmt *Body, |
| 2782 | unsigned DiagID); |
| 2783 | |
| 2784 | /// Warn if a for/while loop statement \p S, which is followed by |
| 2785 | /// \p PossibleBody, has a suspicious null statement as a body. |
| 2786 | void DiagnoseEmptyLoopBody(const Stmt *S, const Stmt *PossibleBody); |
| 2787 | |
| 2788 | /// DiagnoseSelfMove - Emits a warning if a value is moved to itself. |
| 2789 | void DiagnoseSelfMove(const Expr *LHSExpr, const Expr *RHSExpr, |
| 2790 | SourceLocation OpLoc); |
| 2791 | |
| 2792 | bool IsLayoutCompatible(QualType T1, QualType T2) const; |
| 2793 | bool IsPointerInterconvertibleBaseOf(const TypeSourceInfo *Base, |
| 2794 | const TypeSourceInfo *Derived); |
| 2795 | |
| 2796 | /// CheckFunctionCall - Check a direct function call for various correctness |
| 2797 | /// and safety properties not strictly enforced by the C type system. |
| 2798 | bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall, |
| 2799 | const FunctionProtoType *Proto); |
| 2800 | |
| 2801 | enum class EltwiseBuiltinArgTyRestriction { |
| 2802 | None, |
| 2803 | FloatTy, |
| 2804 | IntegerTy, |
| 2805 | SignedIntOrFloatTy, |
| 2806 | }; |
| 2807 | |
| 2808 | /// \param FPOnly restricts the arguments to floating-point types. |
| 2809 | std::optional<QualType> |
| 2810 | BuiltinVectorMath(CallExpr *TheCall, |
| 2811 | EltwiseBuiltinArgTyRestriction ArgTyRestr = |
| 2812 | EltwiseBuiltinArgTyRestriction::None); |
| 2813 | bool BuiltinVectorToScalarMath(CallExpr *TheCall); |
| 2814 | |
| 2815 | void checkLifetimeCaptureBy(FunctionDecl *FDecl, bool IsMemberFunction, |
| 2816 | const Expr *ThisArg, ArrayRef<const Expr *> Args); |
| 2817 | |
| 2818 | /// Handles the checks for format strings, non-POD arguments to vararg |
| 2819 | /// functions, NULL arguments passed to non-NULL parameters, diagnose_if |
| 2820 | /// attributes and AArch64 SME attributes. |
| 2821 | void checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, |
| 2822 | const Expr *ThisArg, ArrayRef<const Expr *> Args, |
| 2823 | bool IsMemberFunction, SourceLocation Loc, SourceRange Range, |
| 2824 | VariadicCallType CallType); |
| 2825 | |
| 2826 | /// Verify that two format strings (as understood by attribute(format) and |
| 2827 | /// attribute(format_matches) are compatible. If they are incompatible, |
| 2828 | /// diagnostics are emitted with the assumption that \c |
| 2829 | /// AuthoritativeFormatString is correct and |
| 2830 | /// \c TestedFormatString is wrong. If \c FunctionCallArg is provided, |
| 2831 | /// diagnostics will point to it and a note will refer to \c |
| 2832 | /// TestedFormatString or \c AuthoritativeFormatString as appropriate. |
| 2833 | bool |
| 2834 | CheckFormatStringsCompatible(FormatStringType FST, |
| 2835 | const StringLiteral *AuthoritativeFormatString, |
| 2836 | const StringLiteral *TestedFormatString, |
| 2837 | const Expr *FunctionCallArg = nullptr); |
| 2838 | |
| 2839 | /// Verify that one format string (as understood by attribute(format)) is |
| 2840 | /// self-consistent; for instance, that it doesn't have multiple positional |
| 2841 | /// arguments referring to the same argument in incompatible ways. Diagnose |
| 2842 | /// if it isn't. |
| 2843 | bool ValidateFormatString(FormatStringType FST, const StringLiteral *Str); |
| 2844 | |
| 2845 | /// \brief Enforce the bounds of a TCB |
| 2846 | /// CheckTCBEnforcement - Enforces that every function in a named TCB only |
| 2847 | /// directly calls other functions in the same TCB as marked by the |
| 2848 | /// enforce_tcb and enforce_tcb_leaf attributes. |
| 2849 | void CheckTCBEnforcement(const SourceLocation CallExprLoc, |
| 2850 | const NamedDecl *Callee); |
| 2851 | |
| 2852 | void CheckConstrainedAuto(const AutoType *AutoT, SourceLocation Loc); |
| 2853 | |
| 2854 | /// BuiltinConstantArg - Handle a check if argument ArgNum of CallExpr |
| 2855 | /// TheCall is a constant expression. |
| 2856 | bool BuiltinConstantArg(CallExpr *TheCall, unsigned ArgNum, |
| 2857 | llvm::APSInt &Result); |
| 2858 | |
| 2859 | /// BuiltinConstantArgRange - Handle a check if argument ArgNum of CallExpr |
| 2860 | /// TheCall is a constant expression in the range [Low, High]. |
| 2861 | bool BuiltinConstantArgRange(CallExpr *TheCall, unsigned ArgNum, int Low, |
| 2862 | int High, bool RangeIsError = true); |
| 2863 | |
| 2864 | /// BuiltinConstantArgMultiple - Handle a check if argument ArgNum of CallExpr |
| 2865 | /// TheCall is a constant expression is a multiple of Num.. |
| 2866 | bool BuiltinConstantArgMultiple(CallExpr *TheCall, unsigned ArgNum, |
| 2867 | unsigned Multiple); |
| 2868 | |
| 2869 | /// BuiltinConstantArgPower2 - Check if argument ArgNum of TheCall is a |
| 2870 | /// constant expression representing a power of 2. |
| 2871 | bool BuiltinConstantArgPower2(CallExpr *TheCall, unsigned ArgNum); |
| 2872 | |
| 2873 | /// BuiltinConstantArgShiftedByte - Check if argument ArgNum of TheCall is |
| 2874 | /// a constant expression representing an arbitrary byte value shifted left by |
| 2875 | /// a multiple of 8 bits. |
| 2876 | bool BuiltinConstantArgShiftedByte(CallExpr *TheCall, unsigned ArgNum, |
| 2877 | unsigned ArgBits); |
| 2878 | |
| 2879 | /// BuiltinConstantArgShiftedByteOr0xFF - Check if argument ArgNum of |
| 2880 | /// TheCall is a constant expression representing either a shifted byte value, |
| 2881 | /// or a value of the form 0x??FF (i.e. a member of the arithmetic progression |
| 2882 | /// 0x00FF, 0x01FF, ..., 0xFFFF). This strange range check is needed for some |
| 2883 | /// Arm MVE intrinsics. |
| 2884 | bool BuiltinConstantArgShiftedByteOrXXFF(CallExpr *TheCall, unsigned ArgNum, |
| 2885 | unsigned ArgBits); |
| 2886 | |
| 2887 | /// Checks that a call expression's argument count is at least the desired |
| 2888 | /// number. This is useful when doing custom type-checking on a variadic |
| 2889 | /// function. Returns true on error. |
| 2890 | bool checkArgCountAtLeast(CallExpr *Call, unsigned MinArgCount); |
| 2891 | |
| 2892 | /// Checks that a call expression's argument count is at most the desired |
| 2893 | /// number. This is useful when doing custom type-checking on a variadic |
| 2894 | /// function. Returns true on error. |
| 2895 | bool checkArgCountAtMost(CallExpr *Call, unsigned MaxArgCount); |
| 2896 | |
| 2897 | /// Checks that a call expression's argument count is in the desired range. |
| 2898 | /// This is useful when doing custom type-checking on a variadic function. |
| 2899 | /// Returns true on error. |
| 2900 | bool checkArgCountRange(CallExpr *Call, unsigned MinArgCount, |
| 2901 | unsigned MaxArgCount); |
| 2902 | |
| 2903 | /// Checks that a call expression's argument count is the desired number. |
| 2904 | /// This is useful when doing custom type-checking. Returns true on error. |
| 2905 | bool checkArgCount(CallExpr *Call, unsigned DesiredArgCount); |
| 2906 | |
| 2907 | /// Returns true if the argument consists of one contiguous run of 1s with any |
| 2908 | /// number of 0s on either side. The 1s are allowed to wrap from LSB to MSB, |
| 2909 | /// so 0x000FFF0, 0x0000FFFF, 0xFF0000FF, 0x0 are all runs. 0x0F0F0000 is not, |
| 2910 | /// since all 1s are not contiguous. |
| 2911 | bool ValueIsRunOfOnes(CallExpr *TheCall, unsigned ArgNum); |
| 2912 | |
| 2913 | void CheckImplicitConversion(Expr *E, QualType T, SourceLocation CC, |
| 2914 | bool *ICContext = nullptr, |
| 2915 | bool IsListInit = false); |
| 2916 | |
| 2917 | /// Check for overflow behavior type related implicit conversion diagnostics. |
| 2918 | /// Returns true if OBT-related diagnostic was issued, false otherwise. |
| 2919 | bool CheckOverflowBehaviorTypeConversion(Expr *E, QualType T, |
| 2920 | SourceLocation CC); |
| 2921 | |
| 2922 | bool |
| 2923 | BuiltinElementwiseTernaryMath(CallExpr *TheCall, |
| 2924 | EltwiseBuiltinArgTyRestriction ArgTyRestr = |
| 2925 | EltwiseBuiltinArgTyRestriction::FloatTy); |
| 2926 | bool PrepareBuiltinElementwiseMathOneArgCall( |
| 2927 | CallExpr *TheCall, EltwiseBuiltinArgTyRestriction ArgTyRestr = |
| 2928 | EltwiseBuiltinArgTyRestriction::None); |
| 2929 | |
| 2930 | private: |
| 2931 | void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, |
| 2932 | const ArraySubscriptExpr *ASE = nullptr, |
| 2933 | bool AllowOnePastEnd = true, bool IndexNegated = false); |
| 2934 | void CheckArrayAccess(const Expr *E); |
| 2935 | |
| 2936 | bool CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall, |
| 2937 | const FunctionProtoType *Proto); |
| 2938 | |
| 2939 | /// Checks function calls when a FunctionDecl or a NamedDecl is not available, |
| 2940 | /// such as function pointers returned from functions. |
| 2941 | bool CheckOtherCall(CallExpr *TheCall, const FunctionProtoType *Proto); |
| 2942 | |
| 2943 | /// CheckConstructorCall - Check a constructor call for correctness and safety |
| 2944 | /// properties not enforced by the C type system. |
| 2945 | void CheckConstructorCall(FunctionDecl *FDecl, QualType ThisType, |
| 2946 | ArrayRef<const Expr *> Args, |
| 2947 | const FunctionProtoType *Proto, SourceLocation Loc); |
| 2948 | |
| 2949 | /// Warn if a pointer or reference argument passed to a function points to an |
| 2950 | /// object that is less aligned than the parameter. This can happen when |
| 2951 | /// creating a typedef with a lower alignment than the original type and then |
| 2952 | /// calling functions defined in terms of the original type. |
| 2953 | void CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl, |
| 2954 | StringRef ParamName, QualType ArgTy, QualType ParamTy); |
| 2955 | |
| 2956 | ExprResult CheckOSLogFormatStringArg(Expr *Arg); |
| 2957 | |
| 2958 | ExprResult CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, |
| 2959 | CallExpr *TheCall); |
| 2960 | |
| 2961 | bool CheckTSBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
| 2962 | CallExpr *TheCall); |
| 2963 | |
| 2964 | void checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD, CallExpr *TheCall); |
| 2965 | |
| 2966 | /// Check the arguments to '__builtin_va_start', '__builtin_ms_va_start', |
| 2967 | /// or '__builtin_c23_va_start' for validity. Emit an error and return true |
| 2968 | /// on failure; return false on success. |
| 2969 | bool BuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall); |
| 2970 | bool BuiltinVAStartARMMicrosoft(CallExpr *Call); |
| 2971 | |
| 2972 | /// BuiltinUnorderedCompare - Handle functions like __builtin_isgreater and |
| 2973 | /// friends. This is declared to take (...), so we have to check everything. |
| 2974 | bool BuiltinUnorderedCompare(CallExpr *TheCall, unsigned BuiltinID); |
| 2975 | |
| 2976 | /// BuiltinSemaBuiltinFPClassification - Handle functions like |
| 2977 | /// __builtin_isnan and friends. This is declared to take (...), so we have |
| 2978 | /// to check everything. |
| 2979 | bool BuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs, |
| 2980 | unsigned BuiltinID); |
| 2981 | |
| 2982 | /// Perform semantic analysis for a call to __builtin_complex. |
| 2983 | bool BuiltinComplex(CallExpr *TheCall); |
| 2984 | bool BuiltinOSLogFormat(CallExpr *TheCall); |
| 2985 | |
| 2986 | /// BuiltinPrefetch - Handle __builtin_prefetch. |
| 2987 | /// This is declared to take (const void*, ...) and can take two |
| 2988 | /// optional constant int args. |
| 2989 | bool BuiltinPrefetch(CallExpr *TheCall); |
| 2990 | |
| 2991 | /// Handle __builtin_alloca_with_align. This is declared |
| 2992 | /// as (size_t, size_t) where the second size_t must be a power of 2 greater |
| 2993 | /// than 8. |
| 2994 | bool BuiltinAllocaWithAlign(CallExpr *TheCall); |
| 2995 | |
| 2996 | /// BuiltinArithmeticFence - Handle __arithmetic_fence. |
| 2997 | bool BuiltinArithmeticFence(CallExpr *TheCall); |
| 2998 | |
| 2999 | /// BuiltinAssume - Handle __assume (MS Extension). |
| 3000 | /// __assume does not evaluate its arguments, and should warn if its argument |
| 3001 | /// has side effects. |
| 3002 | bool BuiltinAssume(CallExpr *TheCall); |
| 3003 | |
| 3004 | /// Handle __builtin_assume_aligned. This is declared |
| 3005 | /// as (const void*, size_t, ...) and can take one optional constant int arg. |
| 3006 | bool BuiltinAssumeAligned(CallExpr *TheCall); |
| 3007 | |
| 3008 | /// BuiltinLongjmp - Handle __builtin_longjmp(void *env[5], int val). |
| 3009 | /// This checks that the target supports __builtin_longjmp and |
| 3010 | /// that val is a constant 1. |
| 3011 | bool BuiltinLongjmp(CallExpr *TheCall); |
| 3012 | |
| 3013 | /// BuiltinSetjmp - Handle __builtin_setjmp(void *env[5]). |
| 3014 | /// This checks that the target supports __builtin_setjmp. |
| 3015 | bool BuiltinSetjmp(CallExpr *TheCall); |
| 3016 | |
| 3017 | /// We have a call to a function like __sync_fetch_and_add, which is an |
| 3018 | /// overloaded function based on the pointer type of its first argument. |
| 3019 | /// The main BuildCallExpr routines have already promoted the types of |
| 3020 | /// arguments because all of these calls are prototyped as void(...). |
| 3021 | /// |
| 3022 | /// This function goes through and does final semantic checking for these |
| 3023 | /// builtins, as well as generating any warnings. |
| 3024 | ExprResult BuiltinAtomicOverloaded(ExprResult TheCallResult); |
| 3025 | |
| 3026 | /// BuiltinNontemporalOverloaded - We have a call to |
| 3027 | /// __builtin_nontemporal_store or __builtin_nontemporal_load, which is an |
| 3028 | /// overloaded function based on the pointer type of its last argument. |
| 3029 | /// |
| 3030 | /// This function goes through and does final semantic checking for these |
| 3031 | /// builtins. |
| 3032 | ExprResult BuiltinNontemporalOverloaded(ExprResult TheCallResult); |
| 3033 | ExprResult AtomicOpsOverloaded(ExprResult TheCallResult, |
| 3034 | AtomicExpr::AtomicOp Op); |
| 3035 | |
| 3036 | /// \param FPOnly restricts the arguments to floating-point types. |
| 3037 | bool BuiltinElementwiseMath(CallExpr *TheCall, |
| 3038 | EltwiseBuiltinArgTyRestriction ArgTyRestr = |
| 3039 | EltwiseBuiltinArgTyRestriction::None); |
| 3040 | bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall); |
| 3041 | |
| 3042 | bool BuiltinNonDeterministicValue(CallExpr *TheCall); |
| 3043 | |
| 3044 | bool CheckInvalidBuiltinCountedByRef(const Expr *E, |
| 3045 | BuiltinCountedByRefKind K); |
| 3046 | bool BuiltinCountedByRef(CallExpr *TheCall); |
| 3047 | |
| 3048 | // Matrix builtin handling. |
| 3049 | ExprResult BuiltinMatrixTranspose(CallExpr *TheCall, ExprResult CallResult); |
| 3050 | ExprResult BuiltinMatrixColumnMajorLoad(CallExpr *TheCall, |
| 3051 | ExprResult CallResult); |
| 3052 | ExprResult BuiltinMatrixColumnMajorStore(CallExpr *TheCall, |
| 3053 | ExprResult CallResult); |
| 3054 | |
| 3055 | /// CheckFormatArguments - Check calls to printf and scanf (and similar |
| 3056 | /// functions) for correct use of format strings. |
| 3057 | /// Returns true if a format string has been fully checked. |
| 3058 | bool CheckFormatArguments(const FormatAttr *Format, |
| 3059 | ArrayRef<const Expr *> Args, bool IsCXXMember, |
| 3060 | VariadicCallType CallType, SourceLocation Loc, |
| 3061 | SourceRange Range, |
| 3062 | llvm::SmallBitVector &CheckedVarArgs); |
| 3063 | bool CheckFormatString(const FormatMatchesAttr *Format, |
| 3064 | ArrayRef<const Expr *> Args, bool IsCXXMember, |
| 3065 | VariadicCallType CallType, SourceLocation Loc, |
| 3066 | SourceRange Range, |
| 3067 | llvm::SmallBitVector &CheckedVarArgs); |
| 3068 | bool CheckFormatArguments(ArrayRef<const Expr *> Args, |
| 3069 | FormatArgumentPassingKind FAPK, |
| 3070 | StringLiteral *ReferenceFormatString, |
| 3071 | unsigned format_idx, unsigned firstDataArg, |
| 3072 | FormatStringType Type, VariadicCallType CallType, |
| 3073 | SourceLocation Loc, SourceRange range, |
| 3074 | llvm::SmallBitVector &CheckedVarArgs); |
| 3075 | |
| 3076 | void CheckInfNaNFunction(const CallExpr *Call, const FunctionDecl *FDecl); |
| 3077 | |
| 3078 | /// Warn when using the wrong abs() function. |
| 3079 | void CheckAbsoluteValueFunction(const CallExpr *Call, |
| 3080 | const FunctionDecl *FDecl); |
| 3081 | |
| 3082 | void CheckMaxUnsignedZero(const CallExpr *Call, const FunctionDecl *FDecl); |
| 3083 | |
| 3084 | /// Check for dangerous or invalid arguments to memset(). |
| 3085 | /// |
| 3086 | /// This issues warnings on known problematic, dangerous or unspecified |
| 3087 | /// arguments to the standard 'memset', 'memcpy', 'memmove', and 'memcmp' |
| 3088 | /// function calls. |
| 3089 | /// |
| 3090 | /// \param Call The call expression to diagnose. |
| 3091 | void CheckMemaccessArguments(const CallExpr *Call, unsigned BId, |
| 3092 | IdentifierInfo *FnName); |
| 3093 | |
| 3094 | bool CheckSizeofMemaccessArgument(const Expr *SizeOfArg, const Expr *Dest, |
| 3095 | IdentifierInfo *FnName); |
| 3096 | // Warn if the user has made the 'size' argument to strlcpy or strlcat |
| 3097 | // be the size of the source, instead of the destination. |
| 3098 | void CheckStrlcpycatArguments(const CallExpr *Call, IdentifierInfo *FnName); |
| 3099 | |
| 3100 | // Warn on anti-patterns as the 'size' argument to strncat. |
| 3101 | // The correct size argument should look like following: |
| 3102 | // strncat(dst, src, sizeof(dst) - strlen(dest) - 1); |
| 3103 | void CheckStrncatArguments(const CallExpr *Call, |
| 3104 | const IdentifierInfo *FnName); |
| 3105 | |
| 3106 | /// Alerts the user that they are attempting to free a non-malloc'd object. |
| 3107 | void CheckFreeArguments(const CallExpr *E); |
| 3108 | |
| 3109 | void CheckReturnValExpr(Expr *RetValExp, QualType lhsType, |
| 3110 | SourceLocation ReturnLoc, bool isObjCMethod = false, |
| 3111 | const AttrVec *Attrs = nullptr, |
| 3112 | const FunctionDecl *FD = nullptr); |
| 3113 | |
| 3114 | /// Diagnoses "dangerous" implicit conversions within the given |
| 3115 | /// expression (which is a full expression). Implements -Wconversion |
| 3116 | /// and -Wsign-compare. |
| 3117 | /// |
| 3118 | /// \param CC the "context" location of the implicit conversion, i.e. |
| 3119 | /// the most location of the syntactic entity requiring the implicit |
| 3120 | /// conversion |
| 3121 | void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); |
| 3122 | |
| 3123 | /// CheckBoolLikeConversion - Check conversion of given expression to boolean. |
| 3124 | /// Input argument E is a logical expression. |
| 3125 | void CheckBoolLikeConversion(Expr *E, SourceLocation CC); |
| 3126 | |
| 3127 | /// Diagnose when expression is an integer constant expression and its |
| 3128 | /// evaluation results in integer overflow |
| 3129 | void CheckForIntOverflow(const Expr *E); |
| 3130 | void CheckUnsequencedOperations(const Expr *E); |
| 3131 | |
| 3132 | /// Perform semantic checks on a completed expression. This will either |
| 3133 | /// be a full-expression or a default argument expression. |
| 3134 | void CheckCompletedExpr(Expr *E, SourceLocation CheckLoc = SourceLocation(), |
| 3135 | bool IsConstexpr = false); |
| 3136 | |
| 3137 | void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, |
| 3138 | Expr *Init); |
| 3139 | |
| 3140 | /// A map from magic value to type information. |
| 3141 | std::unique_ptr<llvm::DenseMap<TypeTagMagicValue, TypeTagData>> |
| 3142 | TypeTagForDatatypeMagicValues; |
| 3143 | |
| 3144 | /// Peform checks on a call of a function with argument_with_type_tag |
| 3145 | /// or pointer_with_type_tag attributes. |
| 3146 | void CheckArgumentWithTypeTag(const ArgumentWithTypeTagAttr *Attr, |
| 3147 | const ArrayRef<const Expr *> ExprArgs, |
| 3148 | SourceLocation CallSiteLoc); |
| 3149 | |
| 3150 | /// Check if we are taking the address of a packed field |
| 3151 | /// as this may be a problem if the pointer value is dereferenced. |
| 3152 | void CheckAddressOfPackedMember(Expr *rhs); |
| 3153 | |
| 3154 | /// Helper class that collects misaligned member designations and |
| 3155 | /// their location info for delayed diagnostics. |
| 3156 | struct MisalignedMember { |
| 3157 | Expr *E; |
| 3158 | RecordDecl *RD; |
| 3159 | ValueDecl *MD; |
| 3160 | CharUnits Alignment; |
| 3161 | |
| 3162 | MisalignedMember() : E(), RD(), MD() {} |
| 3163 | MisalignedMember(Expr *E, RecordDecl *RD, ValueDecl *MD, |
| 3164 | CharUnits Alignment) |
| 3165 | : E(E), RD(RD), MD(MD), Alignment(Alignment) {} |
| 3166 | explicit MisalignedMember(Expr *E) |
| 3167 | : MisalignedMember(E, nullptr, nullptr, CharUnits()) {} |
| 3168 | |
| 3169 | bool operator==(const MisalignedMember &m) { return this->E == m.E; } |
| 3170 | }; |
| 3171 | |
| 3172 | /// Adds an expression to the set of gathered misaligned members. |
| 3173 | void AddPotentialMisalignedMembers(Expr *E, RecordDecl *RD, ValueDecl *MD, |
| 3174 | CharUnits Alignment); |
| 3175 | ///@} |
| 3176 | |
| 3177 | // |
| 3178 | // |
| 3179 | // ------------------------------------------------------------------------- |
| 3180 | // |
| 3181 | // |
| 3182 | |
| 3183 | /// \name C++ Coroutines |
| 3184 | /// Implementations are in SemaCoroutine.cpp |
| 3185 | ///@{ |
| 3186 | |
| 3187 | public: |
| 3188 | /// The C++ "std::coroutine_traits" template, which is defined in |
| 3189 | /// \<coroutine_traits> |
| 3190 | ClassTemplateDecl *StdCoroutineTraitsCache; |
| 3191 | |
| 3192 | bool ActOnCoroutineBodyStart(Scope *S, SourceLocation KwLoc, |
| 3193 | StringRef Keyword); |
| 3194 | ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E); |
| 3195 | ExprResult ActOnCoyieldExpr(Scope *S, SourceLocation KwLoc, Expr *E); |
| 3196 | StmtResult ActOnCoreturnStmt(Scope *S, SourceLocation KwLoc, Expr *E); |
| 3197 | |
| 3198 | ExprResult BuildOperatorCoawaitLookupExpr(Scope *S, SourceLocation Loc); |
| 3199 | ExprResult BuildOperatorCoawaitCall(SourceLocation Loc, Expr *E, |
| 3200 | UnresolvedLookupExpr *Lookup); |
| 3201 | ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, |
| 3202 | Expr *Awaiter, bool IsImplicit = false); |
| 3203 | ExprResult BuildUnresolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, |
| 3204 | UnresolvedLookupExpr *Lookup); |
| 3205 | ExprResult BuildCoyieldExpr(SourceLocation KwLoc, Expr *E); |
| 3206 | StmtResult BuildCoreturnStmt(SourceLocation KwLoc, Expr *E, |
| 3207 | bool IsImplicit = false); |
| 3208 | StmtResult BuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs); |
| 3209 | bool buildCoroutineParameterMoves(SourceLocation Loc); |
| 3210 | VarDecl *buildCoroutinePromise(SourceLocation Loc); |
| 3211 | void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body); |
| 3212 | |
| 3213 | // As a clang extension, enforces that a non-coroutine function must be marked |
| 3214 | // with [[clang::coro_wrapper]] if it returns a type marked with |
| 3215 | // [[clang::coro_return_type]]. |
| 3216 | // Expects that FD is not a coroutine. |
| 3217 | void CheckCoroutineWrapper(FunctionDecl *FD); |
| 3218 | /// Lookup 'coroutine_traits' in std namespace and std::experimental |
| 3219 | /// namespace. The namespace found is recorded in Namespace. |
| 3220 | ClassTemplateDecl *lookupCoroutineTraits(SourceLocation KwLoc, |
| 3221 | SourceLocation FuncLoc); |
| 3222 | /// Check that the expression co_await promise.final_suspend() shall not be |
| 3223 | /// potentially-throwing. |
| 3224 | bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend); |
| 3225 | |
| 3226 | ///@} |
| 3227 | |
| 3228 | // |
| 3229 | // |
| 3230 | // ------------------------------------------------------------------------- |
| 3231 | // |
| 3232 | // |
| 3233 | |
| 3234 | /// \name C++ Scope Specifiers |
| 3235 | /// Implementations are in SemaCXXScopeSpec.cpp |
| 3236 | ///@{ |
| 3237 | |
| 3238 | public: |
| 3239 | // Marks SS invalid if it represents an incomplete type. |
| 3240 | bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); |
| 3241 | // Complete an enum decl, maybe without a scope spec. |
| 3242 | bool RequireCompleteEnumDecl(EnumDecl *D, SourceLocation L, |
| 3243 | CXXScopeSpec *SS = nullptr); |
| 3244 | |
| 3245 | /// Compute the DeclContext that is associated with the given type. |
| 3246 | /// |
| 3247 | /// \param T the type for which we are attempting to find a DeclContext. |
| 3248 | /// |
| 3249 | /// \returns the declaration context represented by the type T, |
| 3250 | /// or NULL if the declaration context cannot be computed (e.g., because it is |
| 3251 | /// dependent and not the current instantiation). |
| 3252 | DeclContext *computeDeclContext(QualType T); |
| 3253 | |
| 3254 | /// Compute the DeclContext that is associated with the given |
| 3255 | /// scope specifier. |
| 3256 | /// |
| 3257 | /// \param SS the C++ scope specifier as it appears in the source |
| 3258 | /// |
| 3259 | /// \param EnteringContext when true, we will be entering the context of |
| 3260 | /// this scope specifier, so we can retrieve the declaration context of a |
| 3261 | /// class template or class template partial specialization even if it is |
| 3262 | /// not the current instantiation. |
| 3263 | /// |
| 3264 | /// \returns the declaration context represented by the scope specifier @p SS, |
| 3265 | /// or NULL if the declaration context cannot be computed (e.g., because it is |
| 3266 | /// dependent and not the current instantiation). |
| 3267 | DeclContext *computeDeclContext(const CXXScopeSpec &SS, |
| 3268 | bool EnteringContext = false); |
| 3269 | bool isDependentScopeSpecifier(const CXXScopeSpec &SS); |
| 3270 | |
| 3271 | /// If the given nested name specifier refers to the current |
| 3272 | /// instantiation, return the declaration that corresponds to that |
| 3273 | /// current instantiation (C++0x [temp.dep.type]p1). |
| 3274 | /// |
| 3275 | /// \param NNS a dependent nested name specifier. |
| 3276 | CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier NNS); |
| 3277 | |
| 3278 | /// The parser has parsed a global nested-name-specifier '::'. |
| 3279 | /// |
| 3280 | /// \param CCLoc The location of the '::'. |
| 3281 | /// |
| 3282 | /// \param SS The nested-name-specifier, which will be updated in-place |
| 3283 | /// to reflect the parsed nested-name-specifier. |
| 3284 | /// |
| 3285 | /// \returns true if an error occurred, false otherwise. |
| 3286 | bool ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc, CXXScopeSpec &SS); |
| 3287 | |
| 3288 | /// The parser has parsed a '__super' nested-name-specifier. |
| 3289 | /// |
| 3290 | /// \param SuperLoc The location of the '__super' keyword. |
| 3291 | /// |
| 3292 | /// \param ColonColonLoc The location of the '::'. |
| 3293 | /// |
| 3294 | /// \param SS The nested-name-specifier, which will be updated in-place |
| 3295 | /// to reflect the parsed nested-name-specifier. |
| 3296 | /// |
| 3297 | /// \returns true if an error occurred, false otherwise. |
| 3298 | bool ActOnSuperScopeSpecifier(SourceLocation SuperLoc, |
| 3299 | SourceLocation ColonColonLoc, CXXScopeSpec &SS); |
| 3300 | |
| 3301 | /// Determines whether the given declaration is an valid acceptable |
| 3302 | /// result for name lookup of a nested-name-specifier. |
| 3303 | /// \param SD Declaration checked for nested-name-specifier. |
| 3304 | /// \param IsExtension If not null and the declaration is accepted as an |
| 3305 | /// extension, the pointed variable is assigned true. |
| 3306 | bool isAcceptableNestedNameSpecifier(const NamedDecl *SD, |
| 3307 | bool *CanCorrect = nullptr); |
| 3308 | |
| 3309 | /// If the given nested-name-specifier begins with a bare identifier |
| 3310 | /// (e.g., Base::), perform name lookup for that identifier as a |
| 3311 | /// nested-name-specifier within the given scope, and return the result of |
| 3312 | /// that name lookup. |
| 3313 | NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier NNS); |
| 3314 | |
| 3315 | /// Keeps information about an identifier in a nested-name-spec. |
| 3316 | /// |
| 3317 | struct NestedNameSpecInfo { |
| 3318 | /// The type of the object, if we're parsing nested-name-specifier in |
| 3319 | /// a member access expression. |
| 3320 | ParsedType ObjectType; |
| 3321 | |
| 3322 | /// The identifier preceding the '::'. |
| 3323 | IdentifierInfo *Identifier; |
| 3324 | |
| 3325 | /// The location of the identifier. |
| 3326 | SourceLocation IdentifierLoc; |
| 3327 | |
| 3328 | /// The location of the '::'. |
| 3329 | SourceLocation CCLoc; |
| 3330 | |
| 3331 | /// Creates info object for the most typical case. |
| 3332 | NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc, |
| 3333 | SourceLocation ColonColonLoc, |
| 3334 | ParsedType ObjectType = ParsedType()) |
| 3335 | : ObjectType(ObjectType), Identifier(II), IdentifierLoc(IdLoc), |
| 3336 | CCLoc(ColonColonLoc) {} |
| 3337 | |
| 3338 | NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc, |
| 3339 | SourceLocation ColonColonLoc, QualType ObjectType) |
| 3340 | : ObjectType(ParsedType::make(P: ObjectType)), Identifier(II), |
| 3341 | IdentifierLoc(IdLoc), CCLoc(ColonColonLoc) {} |
| 3342 | }; |
| 3343 | |
| 3344 | /// Build a new nested-name-specifier for "identifier::", as described |
| 3345 | /// by ActOnCXXNestedNameSpecifier. |
| 3346 | /// |
| 3347 | /// \param S Scope in which the nested-name-specifier occurs. |
| 3348 | /// \param IdInfo Parser information about an identifier in the |
| 3349 | /// nested-name-spec. |
| 3350 | /// \param EnteringContext If true, enter the context specified by the |
| 3351 | /// nested-name-specifier. |
| 3352 | /// \param SS Optional nested name specifier preceding the identifier. |
| 3353 | /// \param ScopeLookupResult Provides the result of name lookup within the |
| 3354 | /// scope of the nested-name-specifier that was computed at template |
| 3355 | /// definition time. |
| 3356 | /// \param ErrorRecoveryLookup Specifies if the method is called to improve |
| 3357 | /// error recovery and what kind of recovery is performed. |
| 3358 | /// \param IsCorrectedToColon If not null, suggestion of replace '::' -> ':' |
| 3359 | /// are allowed. The bool value pointed by this parameter is set to |
| 3360 | /// 'true' if the identifier is treated as if it was followed by ':', |
| 3361 | /// not '::'. |
| 3362 | /// \param OnlyNamespace If true, only considers namespaces in lookup. |
| 3363 | /// |
| 3364 | /// This routine differs only slightly from ActOnCXXNestedNameSpecifier, in |
| 3365 | /// that it contains an extra parameter \p ScopeLookupResult, which provides |
| 3366 | /// the result of name lookup within the scope of the nested-name-specifier |
| 3367 | /// that was computed at template definition time. |
| 3368 | /// |
| 3369 | /// If ErrorRecoveryLookup is true, then this call is used to improve error |
| 3370 | /// recovery. This means that it should not emit diagnostics, it should |
| 3371 | /// just return true on failure. It also means it should only return a valid |
| 3372 | /// scope if it *knows* that the result is correct. It should not return in a |
| 3373 | /// dependent context, for example. Nor will it extend \p SS with the scope |
| 3374 | /// specifier. |
| 3375 | bool BuildCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo, |
| 3376 | bool EnteringContext, CXXScopeSpec &SS, |
| 3377 | NamedDecl *ScopeLookupResult, |
| 3378 | bool ErrorRecoveryLookup, |
| 3379 | bool *IsCorrectedToColon = nullptr, |
| 3380 | bool OnlyNamespace = false); |
| 3381 | |
| 3382 | /// The parser has parsed a nested-name-specifier 'identifier::'. |
| 3383 | /// |
| 3384 | /// \param S The scope in which this nested-name-specifier occurs. |
| 3385 | /// |
| 3386 | /// \param IdInfo Parser information about an identifier in the |
| 3387 | /// nested-name-spec. |
| 3388 | /// |
| 3389 | /// \param EnteringContext Whether we're entering the context nominated by |
| 3390 | /// this nested-name-specifier. |
| 3391 | /// |
| 3392 | /// \param SS The nested-name-specifier, which is both an input |
| 3393 | /// parameter (the nested-name-specifier before this type) and an |
| 3394 | /// output parameter (containing the full nested-name-specifier, |
| 3395 | /// including this new type). |
| 3396 | /// |
| 3397 | /// \param IsCorrectedToColon If not null, suggestions to replace '::' -> ':' |
| 3398 | /// are allowed. The bool value pointed by this parameter is set to 'true' |
| 3399 | /// if the identifier is treated as if it was followed by ':', not '::'. |
| 3400 | /// |
| 3401 | /// \param OnlyNamespace If true, only considers namespaces in lookup. |
| 3402 | /// |
| 3403 | /// \returns true if an error occurred, false otherwise. |
| 3404 | bool ActOnCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo, |
| 3405 | bool EnteringContext, CXXScopeSpec &SS, |
| 3406 | bool *IsCorrectedToColon = nullptr, |
| 3407 | bool OnlyNamespace = false); |
| 3408 | |
| 3409 | /// The parser has parsed a nested-name-specifier |
| 3410 | /// 'template[opt] template-name < template-args >::'. |
| 3411 | /// |
| 3412 | /// \param S The scope in which this nested-name-specifier occurs. |
| 3413 | /// |
| 3414 | /// \param SS The nested-name-specifier, which is both an input |
| 3415 | /// parameter (the nested-name-specifier before this type) and an |
| 3416 | /// output parameter (containing the full nested-name-specifier, |
| 3417 | /// including this new type). |
| 3418 | /// |
| 3419 | /// \param TemplateKWLoc the location of the 'template' keyword, if any. |
| 3420 | /// \param TemplateName the template name. |
| 3421 | /// \param TemplateNameLoc The location of the template name. |
| 3422 | /// \param LAngleLoc The location of the opening angle bracket ('<'). |
| 3423 | /// \param TemplateArgs The template arguments. |
| 3424 | /// \param RAngleLoc The location of the closing angle bracket ('>'). |
| 3425 | /// \param CCLoc The location of the '::'. |
| 3426 | /// |
| 3427 | /// \param EnteringContext Whether we're entering the context of the |
| 3428 | /// nested-name-specifier. |
| 3429 | /// |
| 3430 | /// |
| 3431 | /// \returns true if an error occurred, false otherwise. |
| 3432 | bool ActOnCXXNestedNameSpecifier( |
| 3433 | Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
| 3434 | TemplateTy TemplateName, SourceLocation TemplateNameLoc, |
| 3435 | SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, |
| 3436 | SourceLocation RAngleLoc, SourceLocation CCLoc, bool EnteringContext); |
| 3437 | |
| 3438 | bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, const DeclSpec &DS, |
| 3439 | SourceLocation ColonColonLoc); |
| 3440 | |
| 3441 | bool ActOnCXXNestedNameSpecifierIndexedPack(CXXScopeSpec &SS, |
| 3442 | const DeclSpec &DS, |
| 3443 | SourceLocation ColonColonLoc, |
| 3444 | QualType Type); |
| 3445 | |
| 3446 | /// IsInvalidUnlessNestedName - This method is used for error recovery |
| 3447 | /// purposes to determine whether the specified identifier is only valid as |
| 3448 | /// a nested name specifier, for example a namespace name. It is |
| 3449 | /// conservatively correct to always return false from this method. |
| 3450 | /// |
| 3451 | /// The arguments are the same as those passed to ActOnCXXNestedNameSpecifier. |
| 3452 | bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, |
| 3453 | NestedNameSpecInfo &IdInfo, |
| 3454 | bool EnteringContext); |
| 3455 | |
| 3456 | /// Given a C++ nested-name-specifier, produce an annotation value |
| 3457 | /// that the parser can use later to reconstruct the given |
| 3458 | /// nested-name-specifier. |
| 3459 | /// |
| 3460 | /// \param SS A nested-name-specifier. |
| 3461 | /// |
| 3462 | /// \returns A pointer containing all of the information in the |
| 3463 | /// nested-name-specifier \p SS. |
| 3464 | void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS); |
| 3465 | |
| 3466 | /// Given an annotation pointer for a nested-name-specifier, restore |
| 3467 | /// the nested-name-specifier structure. |
| 3468 | /// |
| 3469 | /// \param Annotation The annotation pointer, produced by |
| 3470 | /// \c SaveNestedNameSpecifierAnnotation(). |
| 3471 | /// |
| 3472 | /// \param AnnotationRange The source range corresponding to the annotation. |
| 3473 | /// |
| 3474 | /// \param SS The nested-name-specifier that will be updated with the contents |
| 3475 | /// of the annotation pointer. |
| 3476 | void RestoreNestedNameSpecifierAnnotation(void *Annotation, |
| 3477 | SourceRange AnnotationRange, |
| 3478 | CXXScopeSpec &SS); |
| 3479 | |
| 3480 | bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
| 3481 | |
| 3482 | /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global |
| 3483 | /// scope or nested-name-specifier) is parsed, part of a declarator-id. |
| 3484 | /// After this method is called, according to [C++ 3.4.3p3], names should be |
| 3485 | /// looked up in the declarator-id's scope, until the declarator is parsed and |
| 3486 | /// ActOnCXXExitDeclaratorScope is called. |
| 3487 | /// The 'SS' should be a non-empty valid CXXScopeSpec. |
| 3488 | bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS); |
| 3489 | |
| 3490 | /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously |
| 3491 | /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same |
| 3492 | /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. |
| 3493 | /// Used to indicate that names should revert to being looked up in the |
| 3494 | /// defining scope. |
| 3495 | void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
| 3496 | |
| 3497 | ///@} |
| 3498 | |
| 3499 | // |
| 3500 | // |
| 3501 | // ------------------------------------------------------------------------- |
| 3502 | // |
| 3503 | // |
| 3504 | |
| 3505 | /// \name Declarations |
| 3506 | /// Implementations are in SemaDecl.cpp |
| 3507 | ///@{ |
| 3508 | |
| 3509 | public: |
| 3510 | IdentifierResolver IdResolver; |
| 3511 | |
| 3512 | /// The index of the first InventedParameterInfo that refers to the current |
| 3513 | /// context. |
| 3514 | unsigned InventedParameterInfosStart = 0; |
| 3515 | |
| 3516 | /// A RAII object to temporarily push a declaration context. |
| 3517 | class { |
| 3518 | private: |
| 3519 | Sema &; |
| 3520 | DeclContext *; |
| 3521 | ProcessingContextState ; |
| 3522 | QualType ; |
| 3523 | unsigned ; |
| 3524 | unsigned ; |
| 3525 | |
| 3526 | public: |
| 3527 | (Sema &S, DeclContext *ContextToPush, bool NewThisContext = true) |
| 3528 | : S(S), SavedContext(S.CurContext), |
| 3529 | SavedContextState(S.DelayedDiagnostics.pushUndelayed()), |
| 3530 | SavedCXXThisTypeOverride(S.CXXThisTypeOverride), |
| 3531 | SavedFunctionScopesStart(S.FunctionScopesStart), |
| 3532 | SavedInventedParameterInfosStart(S.InventedParameterInfosStart) { |
| 3533 | assert(ContextToPush && "pushing null context" ); |
| 3534 | S.CurContext = ContextToPush; |
| 3535 | if (NewThisContext) |
| 3536 | S.CXXThisTypeOverride = QualType(); |
| 3537 | // Any saved FunctionScopes do not refer to this context. |
| 3538 | S.FunctionScopesStart = S.FunctionScopes.size(); |
| 3539 | S.InventedParameterInfosStart = S.InventedParameterInfos.size(); |
| 3540 | } |
| 3541 | |
| 3542 | void () { |
| 3543 | if (!SavedContext) |
| 3544 | return; |
| 3545 | S.CurContext = SavedContext; |
| 3546 | S.DelayedDiagnostics.popUndelayed(state: SavedContextState); |
| 3547 | S.CXXThisTypeOverride = SavedCXXThisTypeOverride; |
| 3548 | S.FunctionScopesStart = SavedFunctionScopesStart; |
| 3549 | S.InventedParameterInfosStart = SavedInventedParameterInfosStart; |
| 3550 | SavedContext = nullptr; |
| 3551 | } |
| 3552 | |
| 3553 | () { pop(); } |
| 3554 | (const ContextRAII &) = delete; |
| 3555 | ContextRAII &(const ContextRAII &) = delete; |
| 3556 | }; |
| 3557 | |
| 3558 | void DiagnoseInvalidJumps(Stmt *Body); |
| 3559 | |
| 3560 | /// The function definitions which were renamed as part of typo-correction |
| 3561 | /// to match their respective declarations. We want to keep track of them |
| 3562 | /// to ensure that we don't emit a "redefinition" error if we encounter a |
| 3563 | /// correctly named definition after the renamed definition. |
| 3564 | llvm::SmallPtrSet<const NamedDecl *, 4> TypoCorrectedFunctionDefinitions; |
| 3565 | |
| 3566 | /// A cache of the flags available in enumerations with the flag_bits |
| 3567 | /// attribute. |
| 3568 | mutable llvm::DenseMap<const EnumDecl *, llvm::APInt> FlagBitsCache; |
| 3569 | |
| 3570 | /// A cache of enumerator values for enums checked by -Wassign-enum. |
| 3571 | llvm::DenseMap<const EnumDecl *, llvm::SmallVector<llvm::APSInt>> |
| 3572 | AssignEnumCache; |
| 3573 | |
| 3574 | /// WeakUndeclaredIdentifiers - Identifiers contained in \#pragma weak before |
| 3575 | /// declared. Rare. May alias another identifier, declared or undeclared. |
| 3576 | /// |
| 3577 | /// For aliases, the target identifier is used as a key for eventual |
| 3578 | /// processing when the target is declared. For the single-identifier form, |
| 3579 | /// the sole identifier is used as the key. Each entry is a `SetVector` |
| 3580 | /// (ordered by parse order) of aliases (identified by the alias name) in case |
| 3581 | /// of multiple aliases to the same undeclared identifier. |
| 3582 | llvm::MapVector< |
| 3583 | IdentifierInfo *, |
| 3584 | llvm::SetVector< |
| 3585 | WeakInfo, llvm::SmallVector<WeakInfo, 1u>, |
| 3586 | llvm::SmallDenseSet<WeakInfo, 2u, WeakInfo::DenseMapInfoByAliasOnly>>> |
| 3587 | WeakUndeclaredIdentifiers; |
| 3588 | |
| 3589 | /// ExtnameUndeclaredIdentifiers - Identifiers contained in |
| 3590 | /// \#pragma redefine_extname before declared. Used in Solaris system headers |
| 3591 | /// to define functions that occur in multiple standards to call the version |
| 3592 | /// in the currently selected standard. |
| 3593 | llvm::DenseMap<IdentifierInfo *, AsmLabelAttr *> ExtnameUndeclaredIdentifiers; |
| 3594 | |
| 3595 | /// Set containing all typedefs that are likely unused. |
| 3596 | llvm::SmallSetVector<const TypedefNameDecl *, 4> |
| 3597 | UnusedLocalTypedefNameCandidates; |
| 3598 | |
| 3599 | typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource, |
| 3600 | &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2> |
| 3601 | UnusedFileScopedDeclsType; |
| 3602 | |
| 3603 | /// The set of file scoped decls seen so far that have not been used |
| 3604 | /// and must warn if not used. Only contains the first declaration. |
| 3605 | UnusedFileScopedDeclsType UnusedFileScopedDecls; |
| 3606 | |
| 3607 | typedef LazyVector<VarDecl *, ExternalSemaSource, |
| 3608 | &ExternalSemaSource::ReadTentativeDefinitions, 2, 2> |
| 3609 | TentativeDefinitionsType; |
| 3610 | |
| 3611 | /// All the tentative definitions encountered in the TU. |
| 3612 | TentativeDefinitionsType TentativeDefinitions; |
| 3613 | |
| 3614 | /// All the external declarations encoutered and used in the TU. |
| 3615 | SmallVector<DeclaratorDecl *, 4> ExternalDeclarations; |
| 3616 | |
| 3617 | /// Generally null except when we temporarily switch decl contexts, |
| 3618 | /// like in \see SemaObjC::ActOnObjCTemporaryExitContainerContext. |
| 3619 | DeclContext *OriginalLexicalContext; |
| 3620 | |
| 3621 | /// Is the module scope we are in a C++ Header Unit? |
| 3622 | bool () const { |
| 3623 | return ModuleScopes.empty() ? false |
| 3624 | : ModuleScopes.back().Module->isHeaderUnit(); |
| 3625 | } |
| 3626 | |
| 3627 | /// Get the module owning an entity. |
| 3628 | Module *getOwningModule(const Decl *Entity) { |
| 3629 | return Entity->getOwningModule(); |
| 3630 | } |
| 3631 | |
| 3632 | DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr); |
| 3633 | |
| 3634 | enum class DiagCtorKind { None, Implicit, Typename }; |
| 3635 | /// Returns the TypeDeclType for the given type declaration, |
| 3636 | /// as ASTContext::getTypeDeclType would, but |
| 3637 | /// performs the required semantic checks for name lookup of said entity. |
| 3638 | void checkTypeDeclType(DeclContext *LookupCtx, DiagCtorKind DCK, TypeDecl *TD, |
| 3639 | SourceLocation NameLoc); |
| 3640 | |
| 3641 | /// If the identifier refers to a type name within this scope, |
| 3642 | /// return the declaration of that type. |
| 3643 | /// |
| 3644 | /// This routine performs ordinary name lookup of the identifier II |
| 3645 | /// within the given scope, with optional C++ scope specifier SS, to |
| 3646 | /// determine whether the name refers to a type. If so, returns an |
| 3647 | /// opaque pointer (actually a QualType) corresponding to that |
| 3648 | /// type. Otherwise, returns NULL. |
| 3649 | ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, |
| 3650 | Scope *S, CXXScopeSpec *SS = nullptr, |
| 3651 | bool isClassName = false, bool HasTrailingDot = false, |
| 3652 | ParsedType ObjectType = nullptr, |
| 3653 | bool IsCtorOrDtorName = false, |
| 3654 | bool WantNontrivialTypeSourceInfo = false, |
| 3655 | bool IsClassTemplateDeductionContext = true, |
| 3656 | ImplicitTypenameContext AllowImplicitTypename = |
| 3657 | ImplicitTypenameContext::No, |
| 3658 | IdentifierInfo **CorrectedII = nullptr); |
| 3659 | |
| 3660 | /// isTagName() - This method is called *for error recovery purposes only* |
| 3661 | /// to determine if the specified name is a valid tag name ("struct foo"). If |
| 3662 | /// so, this returns the TST for the tag corresponding to it (TST_enum, |
| 3663 | /// TST_union, TST_struct, TST_interface, TST_class). This is used to |
| 3664 | /// diagnose cases in C where the user forgot to specify the tag. |
| 3665 | TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S); |
| 3666 | |
| 3667 | /// isMicrosoftMissingTypename - In Microsoft mode, within class scope, |
| 3668 | /// if a CXXScopeSpec's type is equal to the type of one of the base classes |
| 3669 | /// then downgrade the missing typename error to a warning. |
| 3670 | /// This is needed for MSVC compatibility; Example: |
| 3671 | /// @code |
| 3672 | /// template<class T> class A { |
| 3673 | /// public: |
| 3674 | /// typedef int TYPE; |
| 3675 | /// }; |
| 3676 | /// template<class T> class B : public A<T> { |
| 3677 | /// public: |
| 3678 | /// A<T>::TYPE a; // no typename required because A<T> is a base class. |
| 3679 | /// }; |
| 3680 | /// @endcode |
| 3681 | bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S); |
| 3682 | void DiagnoseUnknownTypeName(IdentifierInfo *&II, SourceLocation IILoc, |
| 3683 | Scope *S, CXXScopeSpec *SS, |
| 3684 | ParsedType &SuggestedType, |
| 3685 | bool IsTemplateName = false); |
| 3686 | |
| 3687 | /// Attempt to behave like MSVC in situations where lookup of an unqualified |
| 3688 | /// type name has failed in a dependent context. In these situations, we |
| 3689 | /// automatically form a DependentTypeName that will retry lookup in a related |
| 3690 | /// scope during instantiation. |
| 3691 | ParsedType ActOnMSVCUnknownTypeName(const IdentifierInfo &II, |
| 3692 | SourceLocation NameLoc, |
| 3693 | bool IsTemplateTypeArg); |
| 3694 | |
| 3695 | class NameClassification { |
| 3696 | NameClassificationKind Kind; |
| 3697 | union { |
| 3698 | ExprResult Expr; |
| 3699 | NamedDecl *NonTypeDecl; |
| 3700 | TemplateName Template; |
| 3701 | ParsedType Type; |
| 3702 | }; |
| 3703 | |
| 3704 | explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {} |
| 3705 | |
| 3706 | public: |
| 3707 | NameClassification(ParsedType Type) |
| 3708 | : Kind(NameClassificationKind::Type), Type(Type) {} |
| 3709 | |
| 3710 | NameClassification(const IdentifierInfo *Keyword) |
| 3711 | : Kind(NameClassificationKind::Keyword) {} |
| 3712 | |
| 3713 | static NameClassification Error() { |
| 3714 | return NameClassification(NameClassificationKind::Error); |
| 3715 | } |
| 3716 | |
| 3717 | static NameClassification Unknown() { |
| 3718 | return NameClassification(NameClassificationKind::Unknown); |
| 3719 | } |
| 3720 | |
| 3721 | static NameClassification OverloadSet(ExprResult E) { |
| 3722 | NameClassification Result(NameClassificationKind::OverloadSet); |
| 3723 | Result.Expr = E; |
| 3724 | return Result; |
| 3725 | } |
| 3726 | |
| 3727 | static NameClassification NonType(NamedDecl *D) { |
| 3728 | NameClassification Result(NameClassificationKind::NonType); |
| 3729 | Result.NonTypeDecl = D; |
| 3730 | return Result; |
| 3731 | } |
| 3732 | |
| 3733 | static NameClassification UndeclaredNonType() { |
| 3734 | return NameClassification(NameClassificationKind::UndeclaredNonType); |
| 3735 | } |
| 3736 | |
| 3737 | static NameClassification DependentNonType() { |
| 3738 | return NameClassification(NameClassificationKind::DependentNonType); |
| 3739 | } |
| 3740 | |
| 3741 | static NameClassification TypeTemplate(TemplateName Name) { |
| 3742 | NameClassification Result(NameClassificationKind::TypeTemplate); |
| 3743 | Result.Template = Name; |
| 3744 | return Result; |
| 3745 | } |
| 3746 | |
| 3747 | static NameClassification VarTemplate(TemplateName Name) { |
| 3748 | NameClassification Result(NameClassificationKind::VarTemplate); |
| 3749 | Result.Template = Name; |
| 3750 | return Result; |
| 3751 | } |
| 3752 | |
| 3753 | static NameClassification FunctionTemplate(TemplateName Name) { |
| 3754 | NameClassification Result(NameClassificationKind::FunctionTemplate); |
| 3755 | Result.Template = Name; |
| 3756 | return Result; |
| 3757 | } |
| 3758 | |
| 3759 | static NameClassification Concept(TemplateName Name) { |
| 3760 | NameClassification Result(NameClassificationKind::Concept); |
| 3761 | Result.Template = Name; |
| 3762 | return Result; |
| 3763 | } |
| 3764 | |
| 3765 | static NameClassification UndeclaredTemplate(TemplateName Name) { |
| 3766 | NameClassification Result(NameClassificationKind::UndeclaredTemplate); |
| 3767 | Result.Template = Name; |
| 3768 | return Result; |
| 3769 | } |
| 3770 | |
| 3771 | NameClassificationKind getKind() const { return Kind; } |
| 3772 | |
| 3773 | ExprResult getExpression() const { |
| 3774 | assert(Kind == NameClassificationKind::OverloadSet); |
| 3775 | return Expr; |
| 3776 | } |
| 3777 | |
| 3778 | ParsedType getType() const { |
| 3779 | assert(Kind == NameClassificationKind::Type); |
| 3780 | return Type; |
| 3781 | } |
| 3782 | |
| 3783 | NamedDecl *getNonTypeDecl() const { |
| 3784 | assert(Kind == NameClassificationKind::NonType); |
| 3785 | return NonTypeDecl; |
| 3786 | } |
| 3787 | |
| 3788 | TemplateName getTemplateName() const { |
| 3789 | assert(Kind == NameClassificationKind::TypeTemplate || |
| 3790 | Kind == NameClassificationKind::FunctionTemplate || |
| 3791 | Kind == NameClassificationKind::VarTemplate || |
| 3792 | Kind == NameClassificationKind::Concept || |
| 3793 | Kind == NameClassificationKind::UndeclaredTemplate); |
| 3794 | return Template; |
| 3795 | } |
| 3796 | |
| 3797 | TemplateNameKind getTemplateNameKind() const { |
| 3798 | switch (Kind) { |
| 3799 | case NameClassificationKind::TypeTemplate: |
| 3800 | return TNK_Type_template; |
| 3801 | case NameClassificationKind::FunctionTemplate: |
| 3802 | return TNK_Function_template; |
| 3803 | case NameClassificationKind::VarTemplate: |
| 3804 | return TNK_Var_template; |
| 3805 | case NameClassificationKind::Concept: |
| 3806 | return TNK_Concept_template; |
| 3807 | case NameClassificationKind::UndeclaredTemplate: |
| 3808 | return TNK_Undeclared_template; |
| 3809 | default: |
| 3810 | llvm_unreachable("unsupported name classification." ); |
| 3811 | } |
| 3812 | } |
| 3813 | }; |
| 3814 | |
| 3815 | /// Perform name lookup on the given name, classifying it based on |
| 3816 | /// the results of name lookup and the following token. |
| 3817 | /// |
| 3818 | /// This routine is used by the parser to resolve identifiers and help direct |
| 3819 | /// parsing. When the identifier cannot be found, this routine will attempt |
| 3820 | /// to correct the typo and classify based on the resulting name. |
| 3821 | /// |
| 3822 | /// \param S The scope in which we're performing name lookup. |
| 3823 | /// |
| 3824 | /// \param SS The nested-name-specifier that precedes the name. |
| 3825 | /// |
| 3826 | /// \param Name The identifier. If typo correction finds an alternative name, |
| 3827 | /// this pointer parameter will be updated accordingly. |
| 3828 | /// |
| 3829 | /// \param NameLoc The location of the identifier. |
| 3830 | /// |
| 3831 | /// \param NextToken The token following the identifier. Used to help |
| 3832 | /// disambiguate the name. |
| 3833 | /// |
| 3834 | /// \param CCC The correction callback, if typo correction is desired. |
| 3835 | NameClassification ClassifyName(Scope *S, CXXScopeSpec &SS, |
| 3836 | IdentifierInfo *&Name, SourceLocation NameLoc, |
| 3837 | const Token &NextToken, |
| 3838 | CorrectionCandidateCallback *CCC = nullptr); |
| 3839 | |
| 3840 | /// Act on the result of classifying a name as an undeclared (ADL-only) |
| 3841 | /// non-type declaration. |
| 3842 | ExprResult ActOnNameClassifiedAsUndeclaredNonType(IdentifierInfo *Name, |
| 3843 | SourceLocation NameLoc); |
| 3844 | /// Act on the result of classifying a name as an undeclared member of a |
| 3845 | /// dependent base class. |
| 3846 | ExprResult ActOnNameClassifiedAsDependentNonType(const CXXScopeSpec &SS, |
| 3847 | IdentifierInfo *Name, |
| 3848 | SourceLocation NameLoc, |
| 3849 | bool IsAddressOfOperand); |
| 3850 | /// Act on the result of classifying a name as a specific non-type |
| 3851 | /// declaration. |
| 3852 | ExprResult ActOnNameClassifiedAsNonType(Scope *S, const CXXScopeSpec &SS, |
| 3853 | NamedDecl *Found, |
| 3854 | SourceLocation NameLoc, |
| 3855 | const Token &NextToken); |
| 3856 | /// Act on the result of classifying a name as an overload set. |
| 3857 | ExprResult ActOnNameClassifiedAsOverloadSet(Scope *S, Expr *OverloadSet); |
| 3858 | |
| 3859 | /// Describes the detailed kind of a template name. Used in diagnostics. |
| 3860 | enum class TemplateNameKindForDiagnostics { |
| 3861 | ClassTemplate, |
| 3862 | FunctionTemplate, |
| 3863 | VarTemplate, |
| 3864 | AliasTemplate, |
| 3865 | TemplateTemplateParam, |
| 3866 | Concept, |
| 3867 | DependentTemplate |
| 3868 | }; |
| 3869 | TemplateNameKindForDiagnostics |
| 3870 | getTemplateNameKindForDiagnostics(TemplateName Name); |
| 3871 | |
| 3872 | /// Determine whether it's plausible that E was intended to be a |
| 3873 | /// template-name. |
| 3874 | bool mightBeIntendedToBeTemplateName(ExprResult E, bool &Dependent) { |
| 3875 | if (!getLangOpts().CPlusPlus || E.isInvalid()) |
| 3876 | return false; |
| 3877 | Dependent = false; |
| 3878 | if (auto *DRE = dyn_cast<DeclRefExpr>(Val: E.get())) |
| 3879 | return !DRE->hasExplicitTemplateArgs(); |
| 3880 | if (auto *ME = dyn_cast<MemberExpr>(Val: E.get())) |
| 3881 | return !ME->hasExplicitTemplateArgs(); |
| 3882 | Dependent = true; |
| 3883 | if (auto *DSDRE = dyn_cast<DependentScopeDeclRefExpr>(Val: E.get())) |
| 3884 | return !DSDRE->hasExplicitTemplateArgs(); |
| 3885 | if (auto *DSME = dyn_cast<CXXDependentScopeMemberExpr>(Val: E.get())) |
| 3886 | return !DSME->hasExplicitTemplateArgs(); |
| 3887 | // Any additional cases recognized here should also be handled by |
| 3888 | // diagnoseExprIntendedAsTemplateName. |
| 3889 | return false; |
| 3890 | } |
| 3891 | |
| 3892 | void warnOnReservedIdentifier(const NamedDecl *D); |
| 3893 | void warnOnCTypeHiddenInCPlusPlus(const NamedDecl *D); |
| 3894 | |
| 3895 | void ProcessPragmaExport(DeclaratorDecl *newDecl); |
| 3896 | |
| 3897 | Decl *ActOnDeclarator(Scope *S, Declarator &D); |
| 3898 | |
| 3899 | NamedDecl *HandleDeclarator(Scope *S, Declarator &D, |
| 3900 | MultiTemplateParamsArg TemplateParameterLists); |
| 3901 | |
| 3902 | /// Attempt to fold a variable-sized type to a constant-sized type, returning |
| 3903 | /// true if we were successful. |
| 3904 | bool tryToFixVariablyModifiedVarType(TypeSourceInfo *&TInfo, QualType &T, |
| 3905 | SourceLocation Loc, |
| 3906 | unsigned FailedFoldDiagID); |
| 3907 | |
| 3908 | /// Register the given locally-scoped extern "C" declaration so |
| 3909 | /// that it can be found later for redeclarations. We include any extern "C" |
| 3910 | /// declaration that is not visible in the translation unit here, not just |
| 3911 | /// function-scope declarations. |
| 3912 | void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S); |
| 3913 | |
| 3914 | /// DiagnoseClassNameShadow - Implement C++ [class.mem]p13: |
| 3915 | /// If T is the name of a class, then each of the following shall have a |
| 3916 | /// name different from T: |
| 3917 | /// - every static data member of class T; |
| 3918 | /// - every member function of class T |
| 3919 | /// - every member of class T that is itself a type; |
| 3920 | /// \returns true if the declaration name violates these rules. |
| 3921 | bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info); |
| 3922 | |
| 3923 | /// Diagnose a declaration whose declarator-id has the given |
| 3924 | /// nested-name-specifier. |
| 3925 | /// |
| 3926 | /// \param SS The nested-name-specifier of the declarator-id. |
| 3927 | /// |
| 3928 | /// \param DC The declaration context to which the nested-name-specifier |
| 3929 | /// resolves. |
| 3930 | /// |
| 3931 | /// \param Name The name of the entity being declared. |
| 3932 | /// |
| 3933 | /// \param Loc The location of the name of the entity being declared. |
| 3934 | /// |
| 3935 | /// \param IsMemberSpecialization Whether we are declaring a member |
| 3936 | /// specialization. |
| 3937 | /// |
| 3938 | /// \param TemplateId The template-id, if any. |
| 3939 | /// |
| 3940 | /// \returns true if we cannot safely recover from this error, false |
| 3941 | /// otherwise. |
| 3942 | bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, |
| 3943 | DeclarationName Name, SourceLocation Loc, |
| 3944 | TemplateIdAnnotation *TemplateId, |
| 3945 | bool IsMemberSpecialization); |
| 3946 | |
| 3947 | bool checkPointerAuthEnabled(SourceLocation Loc, SourceRange Range); |
| 3948 | |
| 3949 | bool checkConstantPointerAuthKey(Expr *keyExpr, unsigned &key); |
| 3950 | |
| 3951 | bool checkPointerAuthDiscriminatorArg(Expr *Arg, PointerAuthDiscArgKind Kind, |
| 3952 | unsigned &IntVal); |
| 3953 | |
| 3954 | /// Diagnose function specifiers on a declaration of an identifier that |
| 3955 | /// does not identify a function. |
| 3956 | void DiagnoseFunctionSpecifiers(const DeclSpec &DS); |
| 3957 | |
| 3958 | /// Return the declaration shadowed by the given typedef \p D, or null |
| 3959 | /// if it doesn't shadow any declaration or shadowing warnings are disabled. |
| 3960 | NamedDecl *getShadowedDeclaration(const TypedefNameDecl *D, |
| 3961 | const LookupResult &R); |
| 3962 | |
| 3963 | /// Return the declaration shadowed by the given variable \p D, or null |
| 3964 | /// if it doesn't shadow any declaration or shadowing warnings are disabled. |
| 3965 | NamedDecl *getShadowedDeclaration(const VarDecl *D, const LookupResult &R); |
| 3966 | |
| 3967 | /// Return the declaration shadowed by the given variable \p D, or null |
| 3968 | /// if it doesn't shadow any declaration or shadowing warnings are disabled. |
| 3969 | NamedDecl *getShadowedDeclaration(const BindingDecl *D, |
| 3970 | const LookupResult &R); |
| 3971 | /// Diagnose variable or built-in function shadowing. Implements |
| 3972 | /// -Wshadow. |
| 3973 | /// |
| 3974 | /// This method is called whenever a VarDecl is added to a "useful" |
| 3975 | /// scope. |
| 3976 | /// |
| 3977 | /// \param ShadowedDecl the declaration that is shadowed by the given variable |
| 3978 | /// \param R the lookup of the name |
| 3979 | void CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl, |
| 3980 | const LookupResult &R); |
| 3981 | |
| 3982 | /// Check -Wshadow without the advantage of a previous lookup. |
| 3983 | void CheckShadow(Scope *S, VarDecl *D); |
| 3984 | |
| 3985 | /// Warn if 'E', which is an expression that is about to be modified, refers |
| 3986 | /// to a shadowing declaration. |
| 3987 | void CheckShadowingDeclModification(Expr *E, SourceLocation Loc); |
| 3988 | |
| 3989 | /// Diagnose shadowing for variables shadowed in the lambda record \p LambdaRD |
| 3990 | /// when these variables are captured by the lambda. |
| 3991 | void DiagnoseShadowingLambdaDecls(const sema::LambdaScopeInfo *LSI); |
| 3992 | |
| 3993 | void handleTagNumbering(const TagDecl *Tag, Scope *TagScope); |
| 3994 | void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec, |
| 3995 | TypedefNameDecl *NewTD); |
| 3996 | void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D); |
| 3997 | NamedDecl *ActOnTypedefDeclarator(Scope *S, Declarator &D, DeclContext *DC, |
| 3998 | TypeSourceInfo *TInfo, |
| 3999 | LookupResult &Previous); |
| 4000 | |
| 4001 | /// ActOnTypedefNameDecl - Perform semantic checking for a declaration which |
| 4002 | /// declares a typedef-name, either using the 'typedef' type specifier or via |
| 4003 | /// a C++0x [dcl.typedef]p2 alias-declaration: 'using T = A;'. |
| 4004 | NamedDecl *ActOnTypedefNameDecl(Scope *S, DeclContext *DC, TypedefNameDecl *D, |
| 4005 | LookupResult &Previous, bool &Redeclaration); |
| 4006 | NamedDecl *ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, |
| 4007 | TypeSourceInfo *TInfo, |
| 4008 | LookupResult &Previous, |
| 4009 | MultiTemplateParamsArg TemplateParamLists, |
| 4010 | bool &AddToScope, |
| 4011 | ArrayRef<BindingDecl *> Bindings = {}); |
| 4012 | |
| 4013 | private: |
| 4014 | // Perform a check on an AsmLabel to verify its consistency and emit |
| 4015 | // diagnostics in case of an error. |
| 4016 | void CheckAsmLabel(Scope *S, Expr *AsmLabelExpr, StorageClass SC, |
| 4017 | TypeSourceInfo *TInfo, VarDecl *); |
| 4018 | |
| 4019 | public: |
| 4020 | /// Perform semantic checking on a newly-created variable |
| 4021 | /// declaration. |
| 4022 | /// |
| 4023 | /// This routine performs all of the type-checking required for a |
| 4024 | /// variable declaration once it has been built. It is used both to |
| 4025 | /// check variables after they have been parsed and their declarators |
| 4026 | /// have been translated into a declaration, and to check variables |
| 4027 | /// that have been instantiated from a template. |
| 4028 | /// |
| 4029 | /// Sets NewVD->isInvalidDecl() if an error was encountered. |
| 4030 | /// |
| 4031 | /// Returns true if the variable declaration is a redeclaration. |
| 4032 | bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous); |
| 4033 | void CheckVariableDeclarationType(VarDecl *NewVD); |
| 4034 | void CheckCompleteVariableDeclaration(VarDecl *VD); |
| 4035 | |
| 4036 | NamedDecl *ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, |
| 4037 | TypeSourceInfo *TInfo, |
| 4038 | LookupResult &Previous, |
| 4039 | MultiTemplateParamsArg TemplateParamLists, |
| 4040 | bool &AddToScope); |
| 4041 | |
| 4042 | /// AddOverriddenMethods - See if a method overrides any in the base classes, |
| 4043 | /// and if so, check that it's a valid override and remember it. |
| 4044 | bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); |
| 4045 | |
| 4046 | /// Perform semantic checking of a new function declaration. |
| 4047 | /// |
| 4048 | /// Performs semantic analysis of the new function declaration |
| 4049 | /// NewFD. This routine performs all semantic checking that does not |
| 4050 | /// require the actual declarator involved in the declaration, and is |
| 4051 | /// used both for the declaration of functions as they are parsed |
| 4052 | /// (called via ActOnDeclarator) and for the declaration of functions |
| 4053 | /// that have been instantiated via C++ template instantiation (called |
| 4054 | /// via InstantiateDecl). |
| 4055 | /// |
| 4056 | /// \param IsMemberSpecialization whether this new function declaration is |
| 4057 | /// a member specialization (that replaces any definition provided by the |
| 4058 | /// previous declaration). |
| 4059 | /// |
| 4060 | /// This sets NewFD->isInvalidDecl() to true if there was an error. |
| 4061 | /// |
| 4062 | /// \returns true if the function declaration is a redeclaration. |
| 4063 | bool CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, |
| 4064 | LookupResult &Previous, |
| 4065 | bool IsMemberSpecialization, bool DeclIsDefn); |
| 4066 | |
| 4067 | /// Checks if the new declaration declared in dependent context must be |
| 4068 | /// put in the same redeclaration chain as the specified declaration. |
| 4069 | /// |
| 4070 | /// \param D Declaration that is checked. |
| 4071 | /// \param PrevDecl Previous declaration found with proper lookup method for |
| 4072 | /// the same declaration name. |
| 4073 | /// \returns True if D must be added to the redeclaration chain which PrevDecl |
| 4074 | /// belongs to. |
| 4075 | bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl); |
| 4076 | |
| 4077 | /// Determines if we can perform a correct type check for \p D as a |
| 4078 | /// redeclaration of \p PrevDecl. If not, we can generally still perform a |
| 4079 | /// best-effort check. |
| 4080 | /// |
| 4081 | /// \param NewD The new declaration. |
| 4082 | /// \param OldD The old declaration. |
| 4083 | /// \param NewT The portion of the type of the new declaration to check. |
| 4084 | /// \param OldT The portion of the type of the old declaration to check. |
| 4085 | bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD, |
| 4086 | QualType NewT, QualType OldT); |
| 4087 | void CheckMain(FunctionDecl *FD, const DeclSpec &D); |
| 4088 | void CheckMSVCRTEntryPoint(FunctionDecl *FD); |
| 4089 | |
| 4090 | /// Returns an implicit CodeSegAttr if a __declspec(code_seg) is found on a |
| 4091 | /// containing class. Otherwise it will return implicit SectionAttr if the |
| 4092 | /// function is a definition and there is an active value on CodeSegStack |
| 4093 | /// (from the current #pragma code-seg value). |
| 4094 | /// |
| 4095 | /// \param FD Function being declared. |
| 4096 | /// \param IsDefinition Whether it is a definition or just a declaration. |
| 4097 | /// \returns A CodeSegAttr or SectionAttr to apply to the function or |
| 4098 | /// nullptr if no attribute should be added. |
| 4099 | Attr *getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, |
| 4100 | bool IsDefinition); |
| 4101 | |
| 4102 | /// Common checks for a parameter-declaration that should apply to both |
| 4103 | /// function parameters and non-type template parameters. |
| 4104 | void CheckFunctionOrTemplateParamDeclarator(Scope *S, Declarator &D); |
| 4105 | |
| 4106 | /// ActOnParamDeclarator - Called from Parser::ParseFunctionDeclarator() |
| 4107 | /// to introduce parameters into function prototype scope. |
| 4108 | Decl *ActOnParamDeclarator(Scope *S, Declarator &D, |
| 4109 | SourceLocation ExplicitThisLoc = {}); |
| 4110 | |
| 4111 | /// Synthesizes a variable for a parameter arising from a |
| 4112 | /// typedef. |
| 4113 | ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC, SourceLocation Loc, |
| 4114 | QualType T); |
| 4115 | ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc, |
| 4116 | SourceLocation NameLoc, |
| 4117 | const IdentifierInfo *Name, QualType T, |
| 4118 | TypeSourceInfo *TSInfo, StorageClass SC); |
| 4119 | |
| 4120 | /// Emit diagnostics if the initializer or any of its explicit or |
| 4121 | /// implicitly-generated subexpressions require copying or |
| 4122 | /// default-initializing a type that is or contains a C union type that is |
| 4123 | /// non-trivial to copy or default-initialize. |
| 4124 | void checkNonTrivialCUnionInInitializer(const Expr *Init, SourceLocation Loc); |
| 4125 | |
| 4126 | // These flags are passed to checkNonTrivialCUnion. |
| 4127 | enum NonTrivialCUnionKind { |
| 4128 | NTCUK_Init = 0x1, |
| 4129 | NTCUK_Destruct = 0x2, |
| 4130 | NTCUK_Copy = 0x4, |
| 4131 | }; |
| 4132 | |
| 4133 | /// Emit diagnostics if a non-trivial C union type or a struct that contains |
| 4134 | /// a non-trivial C union is used in an invalid context. |
| 4135 | void checkNonTrivialCUnion(QualType QT, SourceLocation Loc, |
| 4136 | NonTrivialCUnionContext UseContext, |
| 4137 | unsigned NonTrivialKind); |
| 4138 | |
| 4139 | /// Certain globally-unique variables might be accidentally duplicated if |
| 4140 | /// built into multiple shared libraries with hidden visibility. This can |
| 4141 | /// cause problems if the variable is mutable, its initialization is |
| 4142 | /// effectful, or its address is taken. |
| 4143 | bool GloballyUniqueObjectMightBeAccidentallyDuplicated(const VarDecl *Dcl); |
| 4144 | void DiagnoseUniqueObjectDuplication(const VarDecl *Dcl); |
| 4145 | |
| 4146 | /// AddInitializerToDecl - Adds the initializer Init to the |
| 4147 | /// declaration dcl. If DirectInit is true, this is C++ direct |
| 4148 | /// initialization rather than copy initialization. |
| 4149 | void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit); |
| 4150 | void ActOnUninitializedDecl(Decl *dcl); |
| 4151 | |
| 4152 | /// ActOnInitializerError - Given that there was an error parsing an |
| 4153 | /// initializer for the given declaration, try to at least re-establish |
| 4154 | /// invariants such as whether a variable's type is either dependent or |
| 4155 | /// complete. |
| 4156 | void ActOnInitializerError(Decl *Dcl); |
| 4157 | |
| 4158 | void ActOnCXXForRangeDecl(Decl *D); |
| 4159 | StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, |
| 4160 | IdentifierInfo *Ident, |
| 4161 | ParsedAttributes &Attrs); |
| 4162 | |
| 4163 | /// Check if VD needs to be dllexport/dllimport due to being in a |
| 4164 | /// dllexport/import function. |
| 4165 | void CheckStaticLocalForDllExport(VarDecl *VD); |
| 4166 | void CheckThreadLocalForLargeAlignment(VarDecl *VD); |
| 4167 | |
| 4168 | /// FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform |
| 4169 | /// any semantic actions necessary after any initializer has been attached. |
| 4170 | void FinalizeDeclaration(Decl *D); |
| 4171 | DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, |
| 4172 | ArrayRef<Decl *> Group); |
| 4173 | |
| 4174 | /// BuildDeclaratorGroup - convert a list of declarations into a declaration |
| 4175 | /// group, performing any necessary semantic checking. |
| 4176 | DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef<Decl *> Group); |
| 4177 | |
| 4178 | /// Should be called on all declarations that might have attached |
| 4179 | /// documentation comments. |
| 4180 | void ActOnDocumentableDecl(Decl *D); |
| 4181 | void ActOnDocumentableDecls(ArrayRef<Decl *> Group); |
| 4182 | |
| 4183 | enum class FnBodyKind { |
| 4184 | /// C++26 [dcl.fct.def.general]p1 |
| 4185 | /// function-body: |
| 4186 | /// ctor-initializer[opt] compound-statement |
| 4187 | /// function-try-block |
| 4188 | Other, |
| 4189 | /// = default ; |
| 4190 | Default, |
| 4191 | /// deleted-function-body |
| 4192 | /// |
| 4193 | /// deleted-function-body: |
| 4194 | /// = delete ; |
| 4195 | /// = delete ( unevaluated-string ) ; |
| 4196 | Delete |
| 4197 | }; |
| 4198 | |
| 4199 | void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, |
| 4200 | SourceLocation LocAfterDecls); |
| 4201 | void CheckForFunctionRedefinition( |
| 4202 | FunctionDecl *FD, const FunctionDecl *EffectiveDefinition = nullptr, |
| 4203 | SkipBodyInfo *SkipBody = nullptr); |
| 4204 | Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D, |
| 4205 | MultiTemplateParamsArg TemplateParamLists, |
| 4206 | SkipBodyInfo *SkipBody = nullptr, |
| 4207 | FnBodyKind BodyKind = FnBodyKind::Other); |
| 4208 | Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D, |
| 4209 | SkipBodyInfo *SkipBody = nullptr, |
| 4210 | FnBodyKind BodyKind = FnBodyKind::Other); |
| 4211 | void applyFunctionAttributesBeforeParsingBody(Decl *FD); |
| 4212 | |
| 4213 | /// Determine whether we can delay parsing the body of a function or |
| 4214 | /// function template until it is used, assuming we don't care about emitting |
| 4215 | /// code for that function. |
| 4216 | /// |
| 4217 | /// This will be \c false if we may need the body of the function in the |
| 4218 | /// middle of parsing an expression (where it's impractical to switch to |
| 4219 | /// parsing a different function), for instance, if it's constexpr in C++11 |
| 4220 | /// or has an 'auto' return type in C++14. These cases are essentially bugs. |
| 4221 | bool canDelayFunctionBody(const Declarator &D); |
| 4222 | |
| 4223 | /// Determine whether we can skip parsing the body of a function |
| 4224 | /// definition, assuming we don't care about analyzing its body or emitting |
| 4225 | /// code for that function. |
| 4226 | /// |
| 4227 | /// This will be \c false only if we may need the body of the function in |
| 4228 | /// order to parse the rest of the program (for instance, if it is |
| 4229 | /// \c constexpr in C++11 or has an 'auto' return type in C++14). |
| 4230 | bool canSkipFunctionBody(Decl *D); |
| 4231 | |
| 4232 | /// Given the set of return statements within a function body, |
| 4233 | /// compute the variables that are subject to the named return value |
| 4234 | /// optimization. |
| 4235 | /// |
| 4236 | /// Each of the variables that is subject to the named return value |
| 4237 | /// optimization will be marked as NRVO variables in the AST, and any |
| 4238 | /// return statement that has a marked NRVO variable as its NRVO candidate can |
| 4239 | /// use the named return value optimization. |
| 4240 | /// |
| 4241 | /// This function applies a very simplistic algorithm for NRVO: if every |
| 4242 | /// return statement in the scope of a variable has the same NRVO candidate, |
| 4243 | /// that candidate is an NRVO variable. |
| 4244 | void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope); |
| 4245 | |
| 4246 | /// Performs semantic analysis at the end of a function body. |
| 4247 | /// |
| 4248 | /// \param RetainFunctionScopeInfo If \c true, the client is responsible for |
| 4249 | /// releasing the associated \p FunctionScopeInfo. This is useful when |
| 4250 | /// building e.g. LambdaExprs. |
| 4251 | Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, |
| 4252 | bool IsInstantiation = false, |
| 4253 | bool RetainFunctionScopeInfo = false); |
| 4254 | Decl *ActOnSkippedFunctionBody(Decl *Decl); |
| 4255 | void ActOnFinishInlineFunctionDef(FunctionDecl *D); |
| 4256 | |
| 4257 | /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an |
| 4258 | /// attribute for which parsing is delayed. |
| 4259 | void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs); |
| 4260 | |
| 4261 | /// Diagnose any unused parameters in the given sequence of |
| 4262 | /// ParmVarDecl pointers. |
| 4263 | void DiagnoseUnusedParameters(ArrayRef<ParmVarDecl *> Parameters); |
| 4264 | |
| 4265 | /// Diagnose whether the size of parameters or return value of a |
| 4266 | /// function or obj-c method definition is pass-by-value and larger than a |
| 4267 | /// specified threshold. |
| 4268 | void |
| 4269 | DiagnoseSizeOfParametersAndReturnValue(ArrayRef<ParmVarDecl *> Parameters, |
| 4270 | QualType ReturnTy, NamedDecl *D); |
| 4271 | |
| 4272 | Decl *ActOnFileScopeAsmDecl(Expr *expr, SourceLocation AsmLoc, |
| 4273 | SourceLocation RParenLoc); |
| 4274 | |
| 4275 | TopLevelStmtDecl *ActOnStartTopLevelStmtDecl(Scope *S); |
| 4276 | void ActOnFinishTopLevelStmtDecl(TopLevelStmtDecl *D, Stmt *Statement); |
| 4277 | |
| 4278 | void ActOnPopScope(SourceLocation Loc, Scope *S); |
| 4279 | |
| 4280 | /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with |
| 4281 | /// no declarator (e.g. "struct foo;") is parsed. |
| 4282 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
| 4283 | const ParsedAttributesView &DeclAttrs, |
| 4284 | RecordDecl *&AnonRecord); |
| 4285 | |
| 4286 | /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with |
| 4287 | /// no declarator (e.g. "struct foo;") is parsed. It also accepts template |
| 4288 | /// parameters to cope with template friend declarations. |
| 4289 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
| 4290 | const ParsedAttributesView &DeclAttrs, |
| 4291 | MultiTemplateParamsArg TemplateParams, |
| 4292 | bool IsExplicitInstantiation, |
| 4293 | RecordDecl *&AnonRecord, |
| 4294 | SourceLocation EllipsisLoc = {}); |
| 4295 | |
| 4296 | /// BuildAnonymousStructOrUnion - Handle the declaration of an |
| 4297 | /// anonymous structure or union. Anonymous unions are a C++ feature |
| 4298 | /// (C++ [class.union]) and a C11 feature; anonymous structures |
| 4299 | /// are a C11 feature and GNU C++ extension. |
| 4300 | Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, AccessSpecifier AS, |
| 4301 | RecordDecl *Record, |
| 4302 | const PrintingPolicy &Policy); |
| 4303 | |
| 4304 | /// Called once it is known whether |
| 4305 | /// a tag declaration is an anonymous union or struct. |
| 4306 | void ActOnDefinedDeclarationSpecifier(Decl *D); |
| 4307 | |
| 4308 | /// Emit diagnostic warnings for placeholder members. |
| 4309 | /// We can only do that after the class is fully constructed, |
| 4310 | /// as anonymous union/structs can insert placeholders |
| 4311 | /// in their parent scope (which might be a Record). |
| 4312 | void DiagPlaceholderFieldDeclDefinitions(RecordDecl *Record); |
| 4313 | |
| 4314 | /// BuildMicrosoftCAnonymousStruct - Handle the declaration of an |
| 4315 | /// Microsoft C anonymous structure. |
| 4316 | /// Ref: http://msdn.microsoft.com/en-us/library/z2cx9y4f.aspx |
| 4317 | /// Example: |
| 4318 | /// |
| 4319 | /// struct A { int a; }; |
| 4320 | /// struct B { struct A; int b; }; |
| 4321 | /// |
| 4322 | /// void foo() { |
| 4323 | /// B var; |
| 4324 | /// var.a = 3; |
| 4325 | /// } |
| 4326 | Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS, |
| 4327 | RecordDecl *Record); |
| 4328 | |
| 4329 | /// Given a non-tag type declaration, returns an enum useful for indicating |
| 4330 | /// what kind of non-tag type this is. |
| 4331 | NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK); |
| 4332 | |
| 4333 | /// Determine whether a tag with a given kind is acceptable |
| 4334 | /// as a redeclaration of the given tag declaration. |
| 4335 | /// |
| 4336 | /// \returns true if the new tag kind is acceptable, false otherwise. |
| 4337 | bool isAcceptableTagRedeclaration(const TagDecl *Previous, TagTypeKind NewTag, |
| 4338 | bool isDefinition, SourceLocation NewTagLoc, |
| 4339 | const IdentifierInfo *Name); |
| 4340 | |
| 4341 | /// This is invoked when we see 'struct foo' or 'struct {'. In the |
| 4342 | /// former case, Name will be non-null. In the later case, Name will be null. |
| 4343 | /// TagSpec indicates what kind of tag this is. TUK indicates whether this is |
| 4344 | /// a reference/declaration/definition of a tag. |
| 4345 | /// |
| 4346 | /// \param IsTypeSpecifier \c true if this is a type-specifier (or |
| 4347 | /// trailing-type-specifier) other than one in an alias-declaration. |
| 4348 | /// |
| 4349 | /// \param SkipBody If non-null, will be set to indicate if the caller should |
| 4350 | /// skip the definition of this tag and treat it as if it were a declaration. |
| 4351 | DeclResult ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, |
| 4352 | SourceLocation KWLoc, CXXScopeSpec &SS, |
| 4353 | IdentifierInfo *Name, SourceLocation NameLoc, |
| 4354 | const ParsedAttributesView &Attr, AccessSpecifier AS, |
| 4355 | SourceLocation ModulePrivateLoc, |
| 4356 | MultiTemplateParamsArg TemplateParameterLists, |
| 4357 | bool &OwnedDecl, bool &IsDependent, |
| 4358 | SourceLocation ScopedEnumKWLoc, |
| 4359 | bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, |
| 4360 | bool IsTypeSpecifier, bool IsTemplateParamOrArg, |
| 4361 | OffsetOfKind OOK, SkipBodyInfo *SkipBody = nullptr); |
| 4362 | |
| 4363 | /// ActOnField - Each field of a C struct/union is passed into this in order |
| 4364 | /// to create a FieldDecl object for it. |
| 4365 | Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, |
| 4366 | Declarator &D, Expr *BitfieldWidth); |
| 4367 | |
| 4368 | /// HandleField - Analyze a field of a C struct or a C++ data member. |
| 4369 | FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, |
| 4370 | Declarator &D, Expr *BitfieldWidth, |
| 4371 | InClassInitStyle InitStyle, AccessSpecifier AS); |
| 4372 | |
| 4373 | /// Build a new FieldDecl and check its well-formedness. |
| 4374 | /// |
| 4375 | /// This routine builds a new FieldDecl given the fields name, type, |
| 4376 | /// record, etc. \p PrevDecl should refer to any previous declaration |
| 4377 | /// with the same name and in the same scope as the field to be |
| 4378 | /// created. |
| 4379 | /// |
| 4380 | /// \returns a new FieldDecl. |
| 4381 | /// |
| 4382 | /// \todo The Declarator argument is a hack. It will be removed once |
| 4383 | FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T, |
| 4384 | TypeSourceInfo *TInfo, RecordDecl *Record, |
| 4385 | SourceLocation Loc, bool Mutable, |
| 4386 | Expr *BitfieldWidth, InClassInitStyle InitStyle, |
| 4387 | SourceLocation TSSL, AccessSpecifier AS, |
| 4388 | NamedDecl *PrevDecl, Declarator *D = nullptr); |
| 4389 | |
| 4390 | bool CheckNontrivialField(FieldDecl *FD); |
| 4391 | |
| 4392 | /// ActOnLastBitfield - This routine handles synthesized bitfields rules for |
| 4393 | /// class and class extensions. For every class \@interface and class |
| 4394 | /// extension \@interface, if the last ivar is a bitfield of any type, |
| 4395 | /// then add an implicit `char :0` ivar to the end of that interface. |
| 4396 | void ActOnLastBitfield(SourceLocation DeclStart, |
| 4397 | SmallVectorImpl<Decl *> &AllIvarDecls); |
| 4398 | |
| 4399 | // This is used for both record definitions and ObjC interface declarations. |
| 4400 | void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, |
| 4401 | ArrayRef<Decl *> Fields, SourceLocation LBrac, |
| 4402 | SourceLocation RBrac, const ParsedAttributesView &AttrList); |
| 4403 | |
| 4404 | /// ActOnTagStartDefinition - Invoked when we have entered the |
| 4405 | /// scope of a tag's definition (e.g., for an enumeration, class, |
| 4406 | /// struct, or union). |
| 4407 | void ActOnTagStartDefinition(Scope *S, Decl *TagDecl); |
| 4408 | |
| 4409 | /// Perform ODR-like check for C/ObjC when merging tag types from modules. |
| 4410 | /// Differently from C++, actually parse the body and reject / error out |
| 4411 | /// in case of a structural mismatch. |
| 4412 | bool ActOnDuplicateDefinition(Scope *S, Decl *Prev, SkipBodyInfo &SkipBody); |
| 4413 | |
| 4414 | typedef void *SkippedDefinitionContext; |
| 4415 | |
| 4416 | /// Invoked when we enter a tag definition that we're skipping. |
| 4417 | SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD); |
| 4418 | |
| 4419 | /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a |
| 4420 | /// C++ record definition's base-specifiers clause and are starting its |
| 4421 | /// member declarations. |
| 4422 | void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl, |
| 4423 | SourceLocation FinalLoc, |
| 4424 | bool IsFinalSpelledSealed, |
| 4425 | bool IsAbstract, |
| 4426 | SourceLocation LBraceLoc); |
| 4427 | |
| 4428 | /// ActOnTagFinishDefinition - Invoked once we have finished parsing |
| 4429 | /// the definition of a tag (enumeration, class, struct, or union). |
| 4430 | void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, |
| 4431 | SourceRange BraceRange); |
| 4432 | |
| 4433 | ASTContext::CXXRecordDeclRelocationInfo |
| 4434 | CheckCXX2CRelocatable(const clang::CXXRecordDecl *D); |
| 4435 | |
| 4436 | void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context); |
| 4437 | |
| 4438 | /// ActOnTagDefinitionError - Invoked when there was an unrecoverable |
| 4439 | /// error parsing the definition of a tag. |
| 4440 | void ActOnTagDefinitionError(Scope *S, Decl *TagDecl); |
| 4441 | |
| 4442 | EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum, |
| 4443 | EnumConstantDecl *LastEnumConst, |
| 4444 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 4445 | Expr *val); |
| 4446 | |
| 4447 | /// Check that this is a valid underlying type for an enum declaration. |
| 4448 | bool CheckEnumUnderlyingType(TypeSourceInfo *TI); |
| 4449 | |
| 4450 | /// Check whether this is a valid redeclaration of a previous enumeration. |
| 4451 | /// \return true if the redeclaration was invalid. |
| 4452 | bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped, |
| 4453 | QualType EnumUnderlyingTy, bool IsFixed, |
| 4454 | const EnumDecl *Prev); |
| 4455 | |
| 4456 | /// Determine whether the body of an anonymous enumeration should be skipped. |
| 4457 | /// \param II The name of the first enumerator. |
| 4458 | SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II, |
| 4459 | SourceLocation IILoc); |
| 4460 | |
| 4461 | Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, |
| 4462 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 4463 | const ParsedAttributesView &Attrs, |
| 4464 | SourceLocation EqualLoc, Expr *Val, |
| 4465 | SkipBodyInfo *SkipBody = nullptr); |
| 4466 | void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange, |
| 4467 | Decl *EnumDecl, ArrayRef<Decl *> Elements, Scope *S, |
| 4468 | const ParsedAttributesView &Attr); |
| 4469 | |
| 4470 | /// Set the current declaration context until it gets popped. |
| 4471 | void PushDeclContext(Scope *S, DeclContext *DC); |
| 4472 | void PopDeclContext(); |
| 4473 | |
| 4474 | /// EnterDeclaratorContext - Used when we must lookup names in the context |
| 4475 | /// of a declarator's nested name specifier. |
| 4476 | void EnterDeclaratorContext(Scope *S, DeclContext *DC); |
| 4477 | void ExitDeclaratorContext(Scope *S); |
| 4478 | |
| 4479 | /// Enter a template parameter scope, after it's been associated with a |
| 4480 | /// particular DeclContext. Causes lookup within the scope to chain through |
| 4481 | /// enclosing contexts in the correct order. |
| 4482 | void EnterTemplatedContext(Scope *S, DeclContext *DC); |
| 4483 | |
| 4484 | /// Push the parameters of D, which must be a function, into scope. |
| 4485 | void ActOnReenterFunctionContext(Scope *S, Decl *D); |
| 4486 | void ActOnExitFunctionContext(); |
| 4487 | |
| 4488 | /// Add this decl to the scope shadowed decl chains. |
| 4489 | void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true); |
| 4490 | |
| 4491 | /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true |
| 4492 | /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns |
| 4493 | /// true if 'D' belongs to the given declaration context. |
| 4494 | /// |
| 4495 | /// \param AllowInlineNamespace If \c true, allow the declaration to be in the |
| 4496 | /// enclosing namespace set of the context, rather than contained |
| 4497 | /// directly within it. |
| 4498 | bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S = nullptr, |
| 4499 | bool AllowInlineNamespace = false) const; |
| 4500 | |
| 4501 | /// Finds the scope corresponding to the given decl context, if it |
| 4502 | /// happens to be an enclosing scope. Otherwise return NULL. |
| 4503 | static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC); |
| 4504 | |
| 4505 | /// Subroutines of ActOnDeclarator(). |
| 4506 | TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, |
| 4507 | TypeSourceInfo *TInfo); |
| 4508 | bool isIncompatibleTypedef(const TypeDecl *Old, TypedefNameDecl *New); |
| 4509 | |
| 4510 | /// mergeDeclAttributes - Copy attributes from the Old decl to the New one. |
| 4511 | void mergeDeclAttributes( |
| 4512 | NamedDecl *New, Decl *Old, |
| 4513 | AvailabilityMergeKind AMK = AvailabilityMergeKind::Redeclaration); |
| 4514 | |
| 4515 | /// CheckAttributesOnDeducedType - Calls Sema functions for attributes that |
| 4516 | /// requires the type to be deduced. |
| 4517 | void CheckAttributesOnDeducedType(Decl *D); |
| 4518 | |
| 4519 | /// MergeTypedefNameDecl - We just parsed a typedef 'New' which has the |
| 4520 | /// same name and scope as a previous declaration 'Old'. Figure out |
| 4521 | /// how to resolve this situation, merging decls or emitting |
| 4522 | /// diagnostics as appropriate. If there was an error, set New to be invalid. |
| 4523 | void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, |
| 4524 | LookupResult &OldDecls); |
| 4525 | |
| 4526 | /// CleanupMergedEnum - We have just merged the decl 'New' by making another |
| 4527 | /// definition visible. |
| 4528 | /// This method performs any necessary cleanup on the parser state to discard |
| 4529 | /// child nodes from newly parsed decl we are retiring. |
| 4530 | void CleanupMergedEnum(Scope *S, Decl *New); |
| 4531 | |
| 4532 | /// MergeFunctionDecl - We just parsed a function 'New' from |
| 4533 | /// declarator D which has the same name and scope as a previous |
| 4534 | /// declaration 'Old'. Figure out how to resolve this situation, |
| 4535 | /// merging decls or emitting diagnostics as appropriate. |
| 4536 | /// |
| 4537 | /// In C++, New and Old must be declarations that are not |
| 4538 | /// overloaded. Use IsOverload to determine whether New and Old are |
| 4539 | /// overloaded, and to select the Old declaration that New should be |
| 4540 | /// merged with. |
| 4541 | /// |
| 4542 | /// Returns true if there was an error, false otherwise. |
| 4543 | bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S, |
| 4544 | bool MergeTypeWithOld, bool NewDeclIsDefn); |
| 4545 | |
| 4546 | /// Completes the merge of two function declarations that are |
| 4547 | /// known to be compatible. |
| 4548 | /// |
| 4549 | /// This routine handles the merging of attributes and other |
| 4550 | /// properties of function declarations from the old declaration to |
| 4551 | /// the new declaration, once we know that New is in fact a |
| 4552 | /// redeclaration of Old. |
| 4553 | /// |
| 4554 | /// \returns false |
| 4555 | bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old, |
| 4556 | Scope *S, bool MergeTypeWithOld); |
| 4557 | void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old); |
| 4558 | |
| 4559 | /// MergeVarDecl - We just parsed a variable 'New' which has the same name |
| 4560 | /// and scope as a previous declaration 'Old'. Figure out how to resolve this |
| 4561 | /// situation, merging decls or emitting diagnostics as appropriate. |
| 4562 | /// |
| 4563 | /// Tentative definition rules (C99 6.9.2p2) are checked by |
| 4564 | /// FinalizeDeclaratorGroup. Unfortunately, we can't analyze tentative |
| 4565 | /// definitions here, since the initializer hasn't been attached. |
| 4566 | void MergeVarDecl(VarDecl *New, LookupResult &Previous); |
| 4567 | |
| 4568 | /// MergeVarDeclTypes - We parsed a variable 'New' which has the same name and |
| 4569 | /// scope as a previous declaration 'Old'. Figure out how to merge their |
| 4570 | /// types, emitting diagnostics as appropriate. |
| 4571 | /// |
| 4572 | /// Declarations using the auto type specifier (C++ [decl.spec.auto]) call |
| 4573 | /// back to here in AddInitializerToDecl. We can't check them before the |
| 4574 | /// initializer is attached. |
| 4575 | void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool MergeTypeWithOld); |
| 4576 | |
| 4577 | /// We've just determined that \p Old and \p New both appear to be definitions |
| 4578 | /// of the same variable. Either diagnose or fix the problem. |
| 4579 | bool checkVarDeclRedefinition(VarDecl *OldDefn, VarDecl *NewDefn); |
| 4580 | void notePreviousDefinition(const NamedDecl *Old, SourceLocation New); |
| 4581 | |
| 4582 | /// Filters out lookup results that don't fall within the given scope |
| 4583 | /// as determined by isDeclInScope. |
| 4584 | void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S, |
| 4585 | bool ConsiderLinkage, bool AllowInlineNamespace); |
| 4586 | |
| 4587 | /// We've determined that \p New is a redeclaration of \p Old. Check that they |
| 4588 | /// have compatible owning modules. |
| 4589 | bool CheckRedeclarationModuleOwnership(NamedDecl *New, NamedDecl *Old); |
| 4590 | |
| 4591 | /// [module.interface]p6: |
| 4592 | /// A redeclaration of an entity X is implicitly exported if X was introduced |
| 4593 | /// by an exported declaration; otherwise it shall not be exported. |
| 4594 | bool CheckRedeclarationExported(NamedDecl *New, NamedDecl *Old); |
| 4595 | |
| 4596 | /// A wrapper function for checking the semantic restrictions of |
| 4597 | /// a redeclaration within a module. |
| 4598 | bool CheckRedeclarationInModule(NamedDecl *New, NamedDecl *Old); |
| 4599 | |
| 4600 | /// Check the redefinition in C++20 Modules. |
| 4601 | /// |
| 4602 | /// [basic.def.odr]p14: |
| 4603 | /// For any definable item D with definitions in multiple translation units, |
| 4604 | /// - if D is a non-inline non-templated function or variable, or |
| 4605 | /// - if the definitions in different translation units do not satisfy the |
| 4606 | /// following requirements, |
| 4607 | /// the program is ill-formed; a diagnostic is required only if the |
| 4608 | /// definable item is attached to a named module and a prior definition is |
| 4609 | /// reachable at the point where a later definition occurs. |
| 4610 | /// - Each such definition shall not be attached to a named module |
| 4611 | /// ([module.unit]). |
| 4612 | /// - Each such definition shall consist of the same sequence of tokens, ... |
| 4613 | /// ... |
| 4614 | /// |
| 4615 | /// Return true if the redefinition is not allowed. Return false otherwise. |
| 4616 | bool IsRedefinitionInModule(const NamedDecl *New, const NamedDecl *Old) const; |
| 4617 | |
| 4618 | bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const; |
| 4619 | |
| 4620 | /// If it's a file scoped decl that must warn if not used, keep track |
| 4621 | /// of it. |
| 4622 | void MarkUnusedFileScopedDecl(const DeclaratorDecl *D); |
| 4623 | |
| 4624 | typedef llvm::function_ref<void(SourceLocation Loc, PartialDiagnostic PD)> |
| 4625 | DiagReceiverTy; |
| 4626 | |
| 4627 | void DiagnoseUnusedNestedTypedefs(const RecordDecl *D); |
| 4628 | void DiagnoseUnusedNestedTypedefs(const RecordDecl *D, |
| 4629 | DiagReceiverTy DiagReceiver); |
| 4630 | void DiagnoseUnusedDecl(const NamedDecl *ND); |
| 4631 | |
| 4632 | /// DiagnoseUnusedDecl - Emit warnings about declarations that are not used |
| 4633 | /// unless they are marked attr(unused). |
| 4634 | void DiagnoseUnusedDecl(const NamedDecl *ND, DiagReceiverTy DiagReceiver); |
| 4635 | |
| 4636 | /// If VD is set but not otherwise used, diagnose, for a parameter or a |
| 4637 | /// variable. |
| 4638 | void DiagnoseUnusedButSetDecl(const VarDecl *VD, DiagReceiverTy DiagReceiver); |
| 4639 | |
| 4640 | /// getNonFieldDeclScope - Retrieves the innermost scope, starting |
| 4641 | /// from S, where a non-field would be declared. This routine copes |
| 4642 | /// with the difference between C and C++ scoping rules in structs and |
| 4643 | /// unions. For example, the following code is well-formed in C but |
| 4644 | /// ill-formed in C++: |
| 4645 | /// @code |
| 4646 | /// struct S6 { |
| 4647 | /// enum { BAR } e; |
| 4648 | /// }; |
| 4649 | /// |
| 4650 | /// void test_S6() { |
| 4651 | /// struct S6 a; |
| 4652 | /// a.e = BAR; |
| 4653 | /// } |
| 4654 | /// @endcode |
| 4655 | /// For the declaration of BAR, this routine will return a different |
| 4656 | /// scope. The scope S will be the scope of the unnamed enumeration |
| 4657 | /// within S6. In C++, this routine will return the scope associated |
| 4658 | /// with S6, because the enumeration's scope is a transparent |
| 4659 | /// context but structures can contain non-field names. In C, this |
| 4660 | /// routine will return the translation unit scope, since the |
| 4661 | /// enumeration's scope is a transparent context and structures cannot |
| 4662 | /// contain non-field names. |
| 4663 | Scope *getNonFieldDeclScope(Scope *S); |
| 4664 | |
| 4665 | FunctionDecl *CreateBuiltin(IdentifierInfo *II, QualType Type, unsigned ID, |
| 4666 | SourceLocation Loc); |
| 4667 | |
| 4668 | /// LazilyCreateBuiltin - The specified Builtin-ID was first used at |
| 4669 | /// file scope. lazily create a decl for it. ForRedeclaration is true |
| 4670 | /// if we're creating this built-in in anticipation of redeclaring the |
| 4671 | /// built-in. |
| 4672 | NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S, |
| 4673 | bool ForRedeclaration, SourceLocation Loc); |
| 4674 | |
| 4675 | /// Get the outermost AttributedType node that sets a calling convention. |
| 4676 | /// Valid types should not have multiple attributes with different CCs. |
| 4677 | const AttributedType *getCallingConvAttributedType(QualType T) const; |
| 4678 | |
| 4679 | /// GetNameForDeclarator - Determine the full declaration name for the |
| 4680 | /// given Declarator. |
| 4681 | DeclarationNameInfo GetNameForDeclarator(Declarator &D); |
| 4682 | |
| 4683 | /// Retrieves the declaration name from a parsed unqualified-id. |
| 4684 | DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name); |
| 4685 | |
| 4686 | /// ParsingInitForAutoVars - a set of declarations with auto types for which |
| 4687 | /// we are currently parsing the initializer. |
| 4688 | llvm::SmallPtrSet<const Decl *, 4> ParsingInitForAutoVars; |
| 4689 | |
| 4690 | /// Look for a locally scoped extern "C" declaration by the given name. |
| 4691 | NamedDecl *findLocallyScopedExternCDecl(DeclarationName Name); |
| 4692 | |
| 4693 | void deduceOpenCLAddressSpace(VarDecl *decl); |
| 4694 | void deduceHLSLAddressSpace(VarDecl *decl); |
| 4695 | |
| 4696 | /// Adjust the \c DeclContext for a function or variable that might be a |
| 4697 | /// function-local external declaration. |
| 4698 | static bool adjustContextForLocalExternDecl(DeclContext *&DC); |
| 4699 | |
| 4700 | void MarkTypoCorrectedFunctionDefinition(const NamedDecl *F); |
| 4701 | |
| 4702 | /// Checks if the variant/multiversion functions are compatible. |
| 4703 | bool areMultiversionVariantFunctionsCompatible( |
| 4704 | const FunctionDecl *OldFD, const FunctionDecl *NewFD, |
| 4705 | const PartialDiagnostic &NoProtoDiagID, |
| 4706 | const PartialDiagnosticAt &NoteCausedDiagIDAt, |
| 4707 | const PartialDiagnosticAt &NoSupportDiagIDAt, |
| 4708 | const PartialDiagnosticAt &DiffDiagIDAt, bool TemplatesSupported, |
| 4709 | bool ConstexprSupported, bool CLinkageMayDiffer); |
| 4710 | |
| 4711 | /// type checking declaration initializers (C99 6.7.8) |
| 4712 | bool CheckForConstantInitializer( |
| 4713 | Expr *Init, unsigned DiagID = diag::err_init_element_not_constant); |
| 4714 | |
| 4715 | QualType deduceVarTypeFromInitializer(VarDecl *VDecl, DeclarationName Name, |
| 4716 | QualType Type, TypeSourceInfo *TSI, |
| 4717 | SourceRange Range, bool DirectInit, |
| 4718 | Expr *Init); |
| 4719 | |
| 4720 | bool DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit, |
| 4721 | Expr *Init); |
| 4722 | |
| 4723 | sema::LambdaScopeInfo *RebuildLambdaScopeInfo(CXXMethodDecl *CallOperator); |
| 4724 | |
| 4725 | // Heuristically tells if the function is `get_return_object` member of a |
| 4726 | // coroutine promise_type by matching the function name. |
| 4727 | static bool CanBeGetReturnObject(const FunctionDecl *FD); |
| 4728 | static bool CanBeGetReturnTypeOnAllocFailure(const FunctionDecl *FD); |
| 4729 | |
| 4730 | /// ImplicitlyDefineFunction - An undeclared identifier was used in a function |
| 4731 | /// call, forming a call to an implicitly defined function (per C99 6.5.1p2). |
| 4732 | NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, |
| 4733 | Scope *S); |
| 4734 | |
| 4735 | /// If this function is a C++ replaceable global allocation function |
| 4736 | /// (C++2a [basic.stc.dynamic.allocation], C++2a [new.delete]), |
| 4737 | /// adds any function attributes that we know a priori based on the standard. |
| 4738 | /// |
| 4739 | /// We need to check for duplicate attributes both here and where user-written |
| 4740 | /// attributes are applied to declarations. |
| 4741 | void AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction( |
| 4742 | FunctionDecl *FD); |
| 4743 | |
| 4744 | /// Adds any function attributes that we know a priori based on |
| 4745 | /// the declaration of this function. |
| 4746 | /// |
| 4747 | /// These attributes can apply both to implicitly-declared builtins |
| 4748 | /// (like __builtin___printf_chk) or to library-declared functions |
| 4749 | /// like NSLog or printf. |
| 4750 | /// |
| 4751 | /// We need to check for duplicate attributes both here and where user-written |
| 4752 | /// attributes are applied to declarations. |
| 4753 | void AddKnownFunctionAttributes(FunctionDecl *FD); |
| 4754 | |
| 4755 | /// VerifyBitField - verifies that a bit field expression is an ICE and has |
| 4756 | /// the correct width, and that the field type is valid. |
| 4757 | /// Returns false on success. |
| 4758 | ExprResult VerifyBitField(SourceLocation FieldLoc, |
| 4759 | const IdentifierInfo *FieldName, QualType FieldTy, |
| 4760 | bool IsMsStruct, Expr *BitWidth); |
| 4761 | |
| 4762 | /// IsValueInFlagEnum - Determine if a value is allowed as part of a flag |
| 4763 | /// enum. If AllowMask is true, then we also allow the complement of a valid |
| 4764 | /// value, to be used as a mask. |
| 4765 | bool IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val, |
| 4766 | bool AllowMask) const; |
| 4767 | |
| 4768 | /// ActOnPragmaWeakID - Called on well formed \#pragma weak ident. |
| 4769 | void ActOnPragmaWeakID(IdentifierInfo *WeakName, SourceLocation PragmaLoc, |
| 4770 | SourceLocation WeakNameLoc); |
| 4771 | |
| 4772 | /// ActOnPragmaRedefineExtname - Called on well formed |
| 4773 | /// \#pragma redefine_extname oldname newname. |
| 4774 | void ActOnPragmaRedefineExtname(IdentifierInfo *WeakName, |
| 4775 | IdentifierInfo *AliasName, |
| 4776 | SourceLocation PragmaLoc, |
| 4777 | SourceLocation WeakNameLoc, |
| 4778 | SourceLocation AliasNameLoc); |
| 4779 | |
| 4780 | /// ActOnPragmaWeakAlias - Called on well formed \#pragma weak ident = ident. |
| 4781 | void ActOnPragmaWeakAlias(IdentifierInfo *WeakName, IdentifierInfo *AliasName, |
| 4782 | SourceLocation PragmaLoc, |
| 4783 | SourceLocation WeakNameLoc, |
| 4784 | SourceLocation AliasNameLoc); |
| 4785 | |
| 4786 | /// Status of the function emission on the CUDA/HIP/OpenMP host/device attrs. |
| 4787 | enum class FunctionEmissionStatus { |
| 4788 | Emitted, |
| 4789 | CUDADiscarded, // Discarded due to CUDA/HIP hostness |
| 4790 | OMPDiscarded, // Discarded due to OpenMP hostness |
| 4791 | TemplateDiscarded, // Discarded due to uninstantiated templates |
| 4792 | Unknown, |
| 4793 | }; |
| 4794 | FunctionEmissionStatus getEmissionStatus(const FunctionDecl *Decl, |
| 4795 | bool Final = false); |
| 4796 | |
| 4797 | // Whether the callee should be ignored in CUDA/HIP/OpenMP host/device check. |
| 4798 | bool shouldIgnoreInHostDeviceCheck(FunctionDecl *Callee); |
| 4799 | |
| 4800 | /// Function or variable declarations to be checked for whether the deferred |
| 4801 | /// diagnostics should be emitted. |
| 4802 | llvm::SmallSetVector<Decl *, 4> DeclsToCheckForDeferredDiags; |
| 4803 | |
| 4804 | private: |
| 4805 | /// Map of current shadowing declarations to shadowed declarations. Warn if |
| 4806 | /// it looks like the user is trying to modify the shadowing declaration. |
| 4807 | llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls; |
| 4808 | |
| 4809 | // We need this to handle |
| 4810 | // |
| 4811 | // typedef struct { |
| 4812 | // void *foo() { return 0; } |
| 4813 | // } A; |
| 4814 | // |
| 4815 | // When we see foo we don't know if after the typedef we will get 'A' or '*A' |
| 4816 | // for example. If 'A', foo will have external linkage. If we have '*A', |
| 4817 | // foo will have no linkage. Since we can't know until we get to the end |
| 4818 | // of the typedef, this function finds out if D might have non-external |
| 4819 | // linkage. Callers should verify at the end of the TU if it D has external |
| 4820 | // linkage or not. |
| 4821 | static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD); |
| 4822 | |
| 4823 | #include "clang/Sema/AttrIsTypeDependent.inc" |
| 4824 | |
| 4825 | ///@} |
| 4826 | |
| 4827 | // |
| 4828 | // |
| 4829 | // ------------------------------------------------------------------------- |
| 4830 | // |
| 4831 | // |
| 4832 | |
| 4833 | /// \name Declaration Attribute Handling |
| 4834 | /// Implementations are in SemaDeclAttr.cpp |
| 4835 | ///@{ |
| 4836 | |
| 4837 | public: |
| 4838 | /// Describes the kind of priority given to an availability attribute. |
| 4839 | /// |
| 4840 | /// The sum of priorities deteremines the final priority of the attribute. |
| 4841 | /// The final priority determines how the attribute will be merged. |
| 4842 | /// An attribute with a lower priority will always remove higher priority |
| 4843 | /// attributes for the specified platform when it is being applied. An |
| 4844 | /// attribute with a higher priority will not be applied if the declaration |
| 4845 | /// already has an availability attribute with a lower priority for the |
| 4846 | /// specified platform. The final prirority values are not expected to match |
| 4847 | /// the values in this enumeration, but instead should be treated as a plain |
| 4848 | /// integer value. This enumeration just names the priority weights that are |
| 4849 | /// used to calculate that final vaue. |
| 4850 | enum AvailabilityPriority : int { |
| 4851 | /// The availability attribute was specified explicitly next to the |
| 4852 | /// declaration. |
| 4853 | AP_Explicit = 0, |
| 4854 | |
| 4855 | /// The availability attribute was applied using '#pragma clang attribute'. |
| 4856 | AP_PragmaClangAttribute = 1, |
| 4857 | |
| 4858 | /// The availability attribute for a specific platform was inferred from |
| 4859 | /// an availability attribute for another platform. |
| 4860 | AP_InferredFromOtherPlatform = 2 |
| 4861 | }; |
| 4862 | |
| 4863 | /// Describes the reason a calling convention specification was ignored, used |
| 4864 | /// for diagnostics. |
| 4865 | enum class CallingConventionIgnoredReason { |
| 4866 | ForThisTarget = 0, |
| 4867 | VariadicFunction, |
| 4868 | ConstructorDestructor, |
| 4869 | BuiltinFunction |
| 4870 | }; |
| 4871 | |
| 4872 | /// A helper function to provide Attribute Location for the Attr types |
| 4873 | /// AND the ParsedAttr. |
| 4874 | template <typename AttrInfo> |
| 4875 | static std::enable_if_t<std::is_base_of_v<Attr, AttrInfo>, SourceLocation> |
| 4876 | getAttrLoc(const AttrInfo &AL) { |
| 4877 | return AL.getLocation(); |
| 4878 | } |
| 4879 | SourceLocation getAttrLoc(const AttributeCommonInfo &CI); |
| 4880 | |
| 4881 | /// If Expr is a valid integer constant, get the value of the integer |
| 4882 | /// expression and return success or failure. May output an error. |
| 4883 | /// |
| 4884 | /// Negative argument is implicitly converted to unsigned, unless |
| 4885 | /// \p StrictlyUnsigned is true. |
| 4886 | template <typename AttrInfo> |
| 4887 | bool checkUInt32Argument(const AttrInfo &AI, const Expr *Expr, uint32_t &Val, |
| 4888 | unsigned Idx = UINT_MAX, |
| 4889 | bool StrictlyUnsigned = false) { |
| 4890 | std::optional<llvm::APSInt> I = llvm::APSInt(32); |
| 4891 | if (Expr->isTypeDependent() || |
| 4892 | !(I = Expr->getIntegerConstantExpr(Ctx: Context))) { |
| 4893 | if (Idx != UINT_MAX) |
| 4894 | Diag(getAttrLoc(AI), diag::err_attribute_argument_n_type) |
| 4895 | << &AI << Idx << AANT_ArgumentIntegerConstant |
| 4896 | << Expr->getSourceRange(); |
| 4897 | else |
| 4898 | Diag(getAttrLoc(AI), diag::err_attribute_argument_type) |
| 4899 | << &AI << AANT_ArgumentIntegerConstant << Expr->getSourceRange(); |
| 4900 | return false; |
| 4901 | } |
| 4902 | |
| 4903 | if (!I->isIntN(N: 32)) { |
| 4904 | Diag(Loc: Expr->getExprLoc(), DiagID: diag::err_ice_too_large) |
| 4905 | << toString(I: *I, Radix: 10, Signed: false) << 32 << /* Unsigned */ 1; |
| 4906 | return false; |
| 4907 | } |
| 4908 | |
| 4909 | if (StrictlyUnsigned && I->isSigned() && I->isNegative()) { |
| 4910 | Diag(getAttrLoc(AI), diag::err_attribute_requires_positive_integer) |
| 4911 | << &AI << /*non-negative*/ 1; |
| 4912 | return false; |
| 4913 | } |
| 4914 | |
| 4915 | Val = (uint32_t)I->getZExtValue(); |
| 4916 | return true; |
| 4917 | } |
| 4918 | |
| 4919 | /// WeakTopLevelDecl - Translation-unit scoped declarations generated by |
| 4920 | /// \#pragma weak during processing of other Decls. |
| 4921 | /// I couldn't figure out a clean way to generate these in-line, so |
| 4922 | /// we store them here and handle separately -- which is a hack. |
| 4923 | /// It would be best to refactor this. |
| 4924 | SmallVector<Decl *, 2> WeakTopLevelDecl; |
| 4925 | |
| 4926 | /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls |
| 4927 | SmallVectorImpl<Decl *> &WeakTopLevelDecls() { return WeakTopLevelDecl; } |
| 4928 | |
| 4929 | typedef LazyVector<TypedefNameDecl *, ExternalSemaSource, |
| 4930 | &ExternalSemaSource::ReadExtVectorDecls, 2, 2> |
| 4931 | ExtVectorDeclsType; |
| 4932 | |
| 4933 | /// ExtVectorDecls - This is a list all the extended vector types. This allows |
| 4934 | /// us to associate a raw vector type with one of the ext_vector type names. |
| 4935 | /// This is only necessary for issuing pretty diagnostics. |
| 4936 | ExtVectorDeclsType ExtVectorDecls; |
| 4937 | |
| 4938 | /// Check if the argument \p E is a ASCII string literal. If not emit an error |
| 4939 | /// and return false, otherwise set \p Str to the value of the string literal |
| 4940 | /// and return true. |
| 4941 | bool checkStringLiteralArgumentAttr(const AttributeCommonInfo &CI, |
| 4942 | const Expr *E, StringRef &Str, |
| 4943 | SourceLocation *ArgLocation = nullptr); |
| 4944 | |
| 4945 | /// Check if the argument \p ArgNum of \p Attr is a ASCII string literal. |
| 4946 | /// If not emit an error and return false. If the argument is an identifier it |
| 4947 | /// will emit an error with a fixit hint and treat it as if it was a string |
| 4948 | /// literal. |
| 4949 | bool checkStringLiteralArgumentAttr(const ParsedAttr &Attr, unsigned ArgNum, |
| 4950 | StringRef &Str, |
| 4951 | SourceLocation *ArgLocation = nullptr); |
| 4952 | |
| 4953 | /// Determine if type T is a valid subject for a nonnull and similar |
| 4954 | /// attributes. Dependent types are considered valid so they can be checked |
| 4955 | /// during instantiation time. By default, we look through references (the |
| 4956 | /// behavior used by nonnull), but if the second parameter is true, then we |
| 4957 | /// treat a reference type as valid. |
| 4958 | bool isValidPointerAttrType(QualType T, bool RefOkay = false); |
| 4959 | |
| 4960 | /// AddAssumeAlignedAttr - Adds an assume_aligned attribute to a particular |
| 4961 | /// declaration. |
| 4962 | void AddAssumeAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, |
| 4963 | Expr *OE); |
| 4964 | |
| 4965 | /// AddAllocAlignAttr - Adds an alloc_align attribute to a particular |
| 4966 | /// declaration. |
| 4967 | void AddAllocAlignAttr(Decl *D, const AttributeCommonInfo &CI, |
| 4968 | Expr *ParamExpr); |
| 4969 | |
| 4970 | bool CheckAttrTarget(const ParsedAttr &CurrAttr); |
| 4971 | bool CheckAttrNoArgs(const ParsedAttr &CurrAttr); |
| 4972 | |
| 4973 | AvailabilityAttr * |
| 4974 | mergeAvailabilityAttr(NamedDecl *D, const AttributeCommonInfo &CI, |
| 4975 | const IdentifierInfo *Platform, bool Implicit, |
| 4976 | VersionTuple Introduced, VersionTuple Deprecated, |
| 4977 | VersionTuple Obsoleted, bool IsUnavailable, |
| 4978 | StringRef Message, bool IsStrict, StringRef Replacement, |
| 4979 | AvailabilityMergeKind AMK, int Priority, |
| 4980 | const IdentifierInfo *IIEnvironment); |
| 4981 | |
| 4982 | TypeVisibilityAttr * |
| 4983 | mergeTypeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, |
| 4984 | TypeVisibilityAttr::VisibilityType Vis); |
| 4985 | VisibilityAttr *mergeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, |
| 4986 | VisibilityAttr::VisibilityType Vis); |
| 4987 | void mergeVisibilityType(Decl *D, SourceLocation Loc, |
| 4988 | VisibilityAttr::VisibilityType Type); |
| 4989 | SectionAttr *mergeSectionAttr(Decl *D, const AttributeCommonInfo &CI, |
| 4990 | StringRef Name); |
| 4991 | |
| 4992 | /// Used to implement to perform semantic checking on |
| 4993 | /// attribute((section("foo"))) specifiers. |
| 4994 | /// |
| 4995 | /// In this case, "foo" is passed in to be checked. If the section |
| 4996 | /// specifier is invalid, return an Error that indicates the problem. |
| 4997 | /// |
| 4998 | /// This is a simple quality of implementation feature to catch errors |
| 4999 | /// and give good diagnostics in cases when the assembler or code generator |
| 5000 | /// would otherwise reject the section specifier. |
| 5001 | llvm::Error isValidSectionSpecifier(StringRef Str); |
| 5002 | bool checkSectionName(SourceLocation LiteralLoc, StringRef Str); |
| 5003 | CodeSegAttr *mergeCodeSegAttr(Decl *D, const AttributeCommonInfo &CI, |
| 5004 | StringRef Name); |
| 5005 | |
| 5006 | // Check for things we'd like to warn about. Multiversioning issues are |
| 5007 | // handled later in the process, once we know how many exist. |
| 5008 | bool checkTargetAttr(SourceLocation LiteralLoc, StringRef Str); |
| 5009 | |
| 5010 | ErrorAttr *mergeErrorAttr(Decl *D, const AttributeCommonInfo &CI, |
| 5011 | StringRef NewUserDiagnostic); |
| 5012 | FormatAttr *mergeFormatAttr(Decl *D, const AttributeCommonInfo &CI, |
| 5013 | const IdentifierInfo *Format, int FormatIdx, |
| 5014 | int FirstArg); |
| 5015 | FormatMatchesAttr *mergeFormatMatchesAttr(Decl *D, |
| 5016 | const AttributeCommonInfo &CI, |
| 5017 | const IdentifierInfo *Format, |
| 5018 | int FormatIdx, |
| 5019 | StringLiteral *FormatStr); |
| 5020 | ModularFormatAttr *mergeModularFormatAttr(Decl *D, |
| 5021 | const AttributeCommonInfo &CI, |
| 5022 | const IdentifierInfo *ModularImplFn, |
| 5023 | StringRef ImplName, |
| 5024 | MutableArrayRef<StringRef> Aspects); |
| 5025 | |
| 5026 | /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. |
| 5027 | void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, |
| 5028 | bool IsPackExpansion); |
| 5029 | void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, TypeSourceInfo *T, |
| 5030 | bool IsPackExpansion); |
| 5031 | |
| 5032 | /// AddAlignValueAttr - Adds an align_value attribute to a particular |
| 5033 | /// declaration. |
| 5034 | void AddAlignValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E); |
| 5035 | |
| 5036 | /// CreateAnnotationAttr - Creates an annotation Annot with Args arguments. |
| 5037 | Attr *CreateAnnotationAttr(const AttributeCommonInfo &CI, StringRef Annot, |
| 5038 | MutableArrayRef<Expr *> Args); |
| 5039 | Attr *CreateAnnotationAttr(const ParsedAttr &AL); |
| 5040 | |
| 5041 | bool checkMSInheritanceAttrOnDefinition(CXXRecordDecl *RD, SourceRange Range, |
| 5042 | bool BestCase, |
| 5043 | MSInheritanceModel SemanticSpelling); |
| 5044 | |
| 5045 | void CheckAlignasUnderalignment(Decl *D); |
| 5046 | |
| 5047 | /// AddModeAttr - Adds a mode attribute to a particular declaration. |
| 5048 | void AddModeAttr(Decl *D, const AttributeCommonInfo &CI, |
| 5049 | const IdentifierInfo *Name, bool InInstantiation = false); |
| 5050 | AlwaysInlineAttr *mergeAlwaysInlineAttr(Decl *D, |
| 5051 | const AttributeCommonInfo &CI, |
| 5052 | const IdentifierInfo *Ident); |
| 5053 | MinSizeAttr *mergeMinSizeAttr(Decl *D, const AttributeCommonInfo &CI); |
| 5054 | OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, |
| 5055 | const AttributeCommonInfo &CI); |
| 5056 | InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL); |
| 5057 | InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, |
| 5058 | const InternalLinkageAttr &AL); |
| 5059 | |
| 5060 | /// Check validaty of calling convention attribute \p attr. If \p FD |
| 5061 | /// is not null pointer, use \p FD to determine the CUDA/HIP host/device |
| 5062 | /// target. Otherwise, it is specified by \p CFT. |
| 5063 | bool CheckCallingConvAttr( |
| 5064 | const ParsedAttr &attr, CallingConv &CC, const FunctionDecl *FD = nullptr, |
| 5065 | CUDAFunctionTarget CFT = CUDAFunctionTarget::InvalidTarget); |
| 5066 | |
| 5067 | /// Checks a regparm attribute, returning true if it is ill-formed and |
| 5068 | /// otherwise setting numParams to the appropriate value. |
| 5069 | bool CheckRegparmAttr(const ParsedAttr &attr, unsigned &value); |
| 5070 | |
| 5071 | /// Create an CUDALaunchBoundsAttr attribute. |
| 5072 | CUDALaunchBoundsAttr *CreateLaunchBoundsAttr(const AttributeCommonInfo &CI, |
| 5073 | Expr *MaxThreads, |
| 5074 | Expr *MinBlocks, |
| 5075 | Expr *MaxBlocks); |
| 5076 | |
| 5077 | /// AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular |
| 5078 | /// declaration. |
| 5079 | void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI, |
| 5080 | Expr *MaxThreads, Expr *MinBlocks, Expr *MaxBlocks); |
| 5081 | |
| 5082 | /// Add a cluster_dims attribute to a particular declaration. |
| 5083 | CUDAClusterDimsAttr *createClusterDimsAttr(const AttributeCommonInfo &CI, |
| 5084 | Expr *X, Expr *Y, Expr *Z); |
| 5085 | void addClusterDimsAttr(Decl *D, const AttributeCommonInfo &CI, Expr *X, |
| 5086 | Expr *Y, Expr *Z); |
| 5087 | /// Add a no_cluster attribute to a particular declaration. |
| 5088 | void addNoClusterAttr(Decl *D, const AttributeCommonInfo &CI); |
| 5089 | |
| 5090 | enum class RetainOwnershipKind { NS, CF, OS }; |
| 5091 | |
| 5092 | UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI, |
| 5093 | StringRef UuidAsWritten, MSGuidDecl *GuidDecl); |
| 5094 | |
| 5095 | BTFDeclTagAttr *mergeBTFDeclTagAttr(Decl *D, const BTFDeclTagAttr &AL); |
| 5096 | |
| 5097 | DLLImportAttr *mergeDLLImportAttr(Decl *D, const AttributeCommonInfo &CI); |
| 5098 | DLLExportAttr *mergeDLLExportAttr(Decl *D, const AttributeCommonInfo &CI); |
| 5099 | MSInheritanceAttr *mergeMSInheritanceAttr(Decl *D, |
| 5100 | const AttributeCommonInfo &CI, |
| 5101 | bool BestCase, |
| 5102 | MSInheritanceModel Model); |
| 5103 | |
| 5104 | EnforceTCBAttr *mergeEnforceTCBAttr(Decl *D, const EnforceTCBAttr &AL); |
| 5105 | EnforceTCBLeafAttr *mergeEnforceTCBLeafAttr(Decl *D, |
| 5106 | const EnforceTCBLeafAttr &AL); |
| 5107 | |
| 5108 | /// Helper for delayed processing TransparentUnion or |
| 5109 | /// BPFPreserveAccessIndexAttr attribute. |
| 5110 | void ProcessDeclAttributeDelayed(Decl *D, |
| 5111 | const ParsedAttributesView &AttrList); |
| 5112 | |
| 5113 | // Options for ProcessDeclAttributeList(). |
| 5114 | struct ProcessDeclAttributeOptions { |
| 5115 | ProcessDeclAttributeOptions() |
| 5116 | : IncludeCXX11Attributes(true), IgnoreTypeAttributes(false) {} |
| 5117 | |
| 5118 | ProcessDeclAttributeOptions WithIncludeCXX11Attributes(bool Val) { |
| 5119 | ProcessDeclAttributeOptions Result = *this; |
| 5120 | Result.IncludeCXX11Attributes = Val; |
| 5121 | return Result; |
| 5122 | } |
| 5123 | |
| 5124 | ProcessDeclAttributeOptions WithIgnoreTypeAttributes(bool Val) { |
| 5125 | ProcessDeclAttributeOptions Result = *this; |
| 5126 | Result.IgnoreTypeAttributes = Val; |
| 5127 | return Result; |
| 5128 | } |
| 5129 | |
| 5130 | // Should C++11 attributes be processed? |
| 5131 | bool IncludeCXX11Attributes; |
| 5132 | |
| 5133 | // Should any type attributes encountered be ignored? |
| 5134 | // If this option is false, a diagnostic will be emitted for any type |
| 5135 | // attributes of a kind that does not "slide" from the declaration to |
| 5136 | // the decl-specifier-seq. |
| 5137 | bool IgnoreTypeAttributes; |
| 5138 | }; |
| 5139 | |
| 5140 | /// ProcessDeclAttributeList - Apply all the decl attributes in the specified |
| 5141 | /// attribute list to the specified decl, ignoring any type attributes. |
| 5142 | void ProcessDeclAttributeList(Scope *S, Decl *D, |
| 5143 | const ParsedAttributesView &AttrList, |
| 5144 | const ProcessDeclAttributeOptions &Options = |
| 5145 | ProcessDeclAttributeOptions()); |
| 5146 | |
| 5147 | /// Annotation attributes are the only attributes allowed after an access |
| 5148 | /// specifier. |
| 5149 | bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl, |
| 5150 | const ParsedAttributesView &AttrList); |
| 5151 | |
| 5152 | /// checkUnusedDeclAttributes - Given a declarator which is not being |
| 5153 | /// used to build a declaration, complain about any decl attributes |
| 5154 | /// which might be lying around on it. |
| 5155 | void checkUnusedDeclAttributes(Declarator &D); |
| 5156 | |
| 5157 | void DiagnoseUnknownAttribute(const ParsedAttr &AL); |
| 5158 | |
| 5159 | /// DeclClonePragmaWeak - clone existing decl (maybe definition), |
| 5160 | /// \#pragma weak needs a non-definition decl and source may not have one. |
| 5161 | NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, const IdentifierInfo *II, |
| 5162 | SourceLocation Loc); |
| 5163 | |
| 5164 | /// DeclApplyPragmaWeak - A declaration (maybe definition) needs \#pragma weak |
| 5165 | /// applied to it, possibly with an alias. |
| 5166 | void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, const WeakInfo &W); |
| 5167 | |
| 5168 | void ProcessPragmaWeak(Scope *S, Decl *D); |
| 5169 | // Decl attributes - this routine is the top level dispatcher. |
| 5170 | void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD); |
| 5171 | |
| 5172 | void PopParsingDeclaration(ParsingDeclState state, Decl *decl); |
| 5173 | |
| 5174 | /// Given a set of delayed diagnostics, re-emit them as if they had |
| 5175 | /// been delayed in the current context instead of in the given pool. |
| 5176 | /// Essentially, this just moves them to the current pool. |
| 5177 | void redelayDiagnostics(sema::DelayedDiagnosticPool &pool); |
| 5178 | |
| 5179 | /// Check that the type is a plain record with one field being a pointer |
| 5180 | /// type and the other field being an integer. This matches the common |
| 5181 | /// implementation of std::span or sized_allocation_t in P0901R11. |
| 5182 | bool CheckSpanLikeType(const AttributeCommonInfo &CI, const QualType &Ty); |
| 5183 | |
| 5184 | /// Check if IdxExpr is a valid parameter index for a function or |
| 5185 | /// instance method D. May output an error. |
| 5186 | /// |
| 5187 | /// \returns true if IdxExpr is a valid index. |
| 5188 | template <typename AttrInfo> |
| 5189 | bool checkFunctionOrMethodParameterIndex( |
| 5190 | const Decl *D, const AttrInfo &AI, unsigned AttrArgNum, |
| 5191 | const Expr *IdxExpr, ParamIdx &Idx, bool CanIndexImplicitThis = false, |
| 5192 | bool CanIndexVariadicArguments = false) { |
| 5193 | assert(isFunctionOrMethodOrBlockForAttrSubject(D)); |
| 5194 | |
| 5195 | // In C++ the implicit 'this' function parameter also counts. |
| 5196 | // Parameters are counted from one. |
| 5197 | bool HP = hasFunctionProto(D); |
| 5198 | bool HasImplicitThisParam = hasImplicitObjectParameter(D); |
| 5199 | bool IV = HP && isFunctionOrMethodVariadic(D); |
| 5200 | unsigned NumParams = |
| 5201 | (HP ? getFunctionOrMethodNumParams(D) : 0) + HasImplicitThisParam; |
| 5202 | |
| 5203 | std::optional<llvm::APSInt> IdxInt; |
| 5204 | if (IdxExpr->isTypeDependent() || |
| 5205 | !(IdxInt = IdxExpr->getIntegerConstantExpr(Ctx: Context))) { |
| 5206 | Diag(getAttrLoc(AI), diag::err_attribute_argument_n_type) |
| 5207 | << &AI << AttrArgNum << AANT_ArgumentIntegerConstant |
| 5208 | << IdxExpr->getSourceRange(); |
| 5209 | return false; |
| 5210 | } |
| 5211 | |
| 5212 | unsigned IdxSource = IdxInt->getLimitedValue(UINT_MAX); |
| 5213 | if (IdxSource < 1 || |
| 5214 | ((!IV || !CanIndexVariadicArguments) && IdxSource > NumParams)) { |
| 5215 | Diag(getAttrLoc(AI), diag::err_attribute_argument_out_of_bounds) |
| 5216 | << &AI << AttrArgNum << IdxExpr->getSourceRange(); |
| 5217 | return false; |
| 5218 | } |
| 5219 | if (HasImplicitThisParam && !CanIndexImplicitThis) { |
| 5220 | if (IdxSource == 1) { |
| 5221 | Diag(getAttrLoc(AI), diag::err_attribute_invalid_implicit_this_argument) |
| 5222 | << &AI << IdxExpr->getSourceRange(); |
| 5223 | return false; |
| 5224 | } |
| 5225 | } |
| 5226 | |
| 5227 | Idx = ParamIdx(IdxSource, D); |
| 5228 | return true; |
| 5229 | } |
| 5230 | |
| 5231 | ///@} |
| 5232 | |
| 5233 | // |
| 5234 | // |
| 5235 | // ------------------------------------------------------------------------- |
| 5236 | // |
| 5237 | // |
| 5238 | |
| 5239 | /// \name C++ Declarations |
| 5240 | /// Implementations are in SemaDeclCXX.cpp |
| 5241 | ///@{ |
| 5242 | |
| 5243 | public: |
| 5244 | void CheckDelegatingCtorCycles(); |
| 5245 | |
| 5246 | /// Called before parsing a function declarator belonging to a function |
| 5247 | /// declaration. |
| 5248 | void ActOnStartFunctionDeclarationDeclarator(Declarator &D, |
| 5249 | unsigned TemplateParameterDepth); |
| 5250 | |
| 5251 | /// Called after parsing a function declarator belonging to a function |
| 5252 | /// declaration. |
| 5253 | void ActOnFinishFunctionDeclarationDeclarator(Declarator &D); |
| 5254 | |
| 5255 | // Act on C++ namespaces |
| 5256 | Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, |
| 5257 | SourceLocation NamespaceLoc, |
| 5258 | SourceLocation IdentLoc, IdentifierInfo *Ident, |
| 5259 | SourceLocation LBrace, |
| 5260 | const ParsedAttributesView &AttrList, |
| 5261 | UsingDirectiveDecl *&UsingDecl, bool IsNested); |
| 5262 | |
| 5263 | /// ActOnFinishNamespaceDef - This callback is called after a namespace is |
| 5264 | /// exited. Decl is the DeclTy returned by ActOnStartNamespaceDef. |
| 5265 | void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); |
| 5266 | |
| 5267 | NamespaceDecl *getStdNamespace() const; |
| 5268 | |
| 5269 | /// Retrieve the special "std" namespace, which may require us to |
| 5270 | /// implicitly define the namespace. |
| 5271 | NamespaceDecl *getOrCreateStdNamespace(); |
| 5272 | |
| 5273 | CXXRecordDecl *getStdBadAlloc() const; |
| 5274 | EnumDecl *getStdAlignValT() const; |
| 5275 | |
| 5276 | TypeAwareAllocationMode ShouldUseTypeAwareOperatorNewOrDelete() const; |
| 5277 | FunctionDecl *BuildTypeAwareUsualDelete(FunctionTemplateDecl *FnDecl, |
| 5278 | QualType AllocType, SourceLocation); |
| 5279 | |
| 5280 | ValueDecl *tryLookupUnambiguousFieldDecl(RecordDecl *ClassDecl, |
| 5281 | const IdentifierInfo *MemberOrBase); |
| 5282 | |
| 5283 | enum class ComparisonCategoryUsage { |
| 5284 | /// The '<=>' operator was used in an expression and a builtin operator |
| 5285 | /// was selected. |
| 5286 | OperatorInExpression, |
| 5287 | /// A defaulted 'operator<=>' needed the comparison category. This |
| 5288 | /// typically only applies to 'std::strong_ordering', due to the implicit |
| 5289 | /// fallback return value. |
| 5290 | DefaultedOperator, |
| 5291 | }; |
| 5292 | |
| 5293 | /// Lookup the specified comparison category types in the standard |
| 5294 | /// library, an check the VarDecls possibly returned by the operator<=> |
| 5295 | /// builtins for that type. |
| 5296 | /// |
| 5297 | /// \return The type of the comparison category type corresponding to the |
| 5298 | /// specified Kind, or a null type if an error occurs |
| 5299 | QualType CheckComparisonCategoryType(ComparisonCategoryType Kind, |
| 5300 | SourceLocation Loc, |
| 5301 | ComparisonCategoryUsage Usage); |
| 5302 | |
| 5303 | /// Tests whether Ty is an instance of std::initializer_list and, if |
| 5304 | /// it is and Element is not NULL, assigns the element type to Element. |
| 5305 | bool isStdInitializerList(QualType Ty, QualType *Element); |
| 5306 | |
| 5307 | /// Tests whether Ty is an instance of std::type_identity and, if |
| 5308 | /// it is and TypeArgument is not NULL, assigns the element type to Element. |
| 5309 | /// If MalformedDecl is not null, and type_identity was ruled out due to being |
| 5310 | /// incorrectly structured despite having the correct name, the faulty Decl |
| 5311 | /// will be assigned to MalformedDecl. |
| 5312 | bool isStdTypeIdentity(QualType Ty, QualType *TypeArgument, |
| 5313 | const Decl **MalformedDecl = nullptr); |
| 5314 | |
| 5315 | /// Looks for the std::initializer_list template and instantiates it |
| 5316 | /// with Element, or emits an error if it's not found. |
| 5317 | /// |
| 5318 | /// \returns The instantiated template, or null on error. |
| 5319 | QualType BuildStdInitializerList(QualType Element, SourceLocation Loc); |
| 5320 | |
| 5321 | /// Looks for the std::type_identity template and instantiates it |
| 5322 | /// with Type, or returns a null type if type_identity has not been declared |
| 5323 | /// |
| 5324 | /// \returns The instantiated template, or null if std::type_identity is not |
| 5325 | /// declared |
| 5326 | QualType tryBuildStdTypeIdentity(QualType Type, SourceLocation Loc); |
| 5327 | |
| 5328 | /// Determine whether Ctor is an initializer-list constructor, as |
| 5329 | /// defined in [dcl.init.list]p2. |
| 5330 | bool isInitListConstructor(const FunctionDecl *Ctor); |
| 5331 | |
| 5332 | Decl *ActOnUsingDirective(Scope *CurScope, SourceLocation UsingLoc, |
| 5333 | SourceLocation NamespcLoc, CXXScopeSpec &SS, |
| 5334 | SourceLocation IdentLoc, |
| 5335 | IdentifierInfo *NamespcName, |
| 5336 | const ParsedAttributesView &AttrList); |
| 5337 | |
| 5338 | void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); |
| 5339 | |
| 5340 | Decl *ActOnNamespaceAliasDef(Scope *CurScope, SourceLocation NamespaceLoc, |
| 5341 | SourceLocation AliasLoc, IdentifierInfo *Alias, |
| 5342 | CXXScopeSpec &SS, SourceLocation IdentLoc, |
| 5343 | IdentifierInfo *Ident); |
| 5344 | |
| 5345 | /// Remove decls we can't actually see from a lookup being used to declare |
| 5346 | /// shadow using decls. |
| 5347 | /// |
| 5348 | /// \param S - The scope of the potential shadow decl |
| 5349 | /// \param Previous - The lookup of a potential shadow decl's name. |
| 5350 | void FilterUsingLookup(Scope *S, LookupResult &lookup); |
| 5351 | |
| 5352 | /// Hides a using shadow declaration. This is required by the current |
| 5353 | /// using-decl implementation when a resolvable using declaration in a |
| 5354 | /// class is followed by a declaration which would hide or override |
| 5355 | /// one or more of the using decl's targets; for example: |
| 5356 | /// |
| 5357 | /// struct Base { void foo(int); }; |
| 5358 | /// struct Derived : Base { |
| 5359 | /// using Base::foo; |
| 5360 | /// void foo(int); |
| 5361 | /// }; |
| 5362 | /// |
| 5363 | /// The governing language is C++03 [namespace.udecl]p12: |
| 5364 | /// |
| 5365 | /// When a using-declaration brings names from a base class into a |
| 5366 | /// derived class scope, member functions in the derived class |
| 5367 | /// override and/or hide member functions with the same name and |
| 5368 | /// parameter types in a base class (rather than conflicting). |
| 5369 | /// |
| 5370 | /// There are two ways to implement this: |
| 5371 | /// (1) optimistically create shadow decls when they're not hidden |
| 5372 | /// by existing declarations, or |
| 5373 | /// (2) don't create any shadow decls (or at least don't make them |
| 5374 | /// visible) until we've fully parsed/instantiated the class. |
| 5375 | /// The problem with (1) is that we might have to retroactively remove |
| 5376 | /// a shadow decl, which requires several O(n) operations because the |
| 5377 | /// decl structures are (very reasonably) not designed for removal. |
| 5378 | /// (2) avoids this but is very fiddly and phase-dependent. |
| 5379 | void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow); |
| 5380 | |
| 5381 | /// Determines whether to create a using shadow decl for a particular |
| 5382 | /// decl, given the set of decls existing prior to this using lookup. |
| 5383 | bool CheckUsingShadowDecl(BaseUsingDecl *BUD, NamedDecl *Target, |
| 5384 | const LookupResult &PreviousDecls, |
| 5385 | UsingShadowDecl *&PrevShadow); |
| 5386 | |
| 5387 | /// Builds a shadow declaration corresponding to a 'using' declaration. |
| 5388 | UsingShadowDecl *BuildUsingShadowDecl(Scope *S, BaseUsingDecl *BUD, |
| 5389 | NamedDecl *Target, |
| 5390 | UsingShadowDecl *PrevDecl); |
| 5391 | |
| 5392 | /// Checks that the given using declaration is not an invalid |
| 5393 | /// redeclaration. Note that this is checking only for the using decl |
| 5394 | /// itself, not for any ill-formedness among the UsingShadowDecls. |
| 5395 | bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, |
| 5396 | bool HasTypenameKeyword, |
| 5397 | const CXXScopeSpec &SS, |
| 5398 | SourceLocation NameLoc, |
| 5399 | const LookupResult &Previous); |
| 5400 | |
| 5401 | /// Checks that the given nested-name qualifier used in a using decl |
| 5402 | /// in the current context is appropriately related to the current |
| 5403 | /// scope. If an error is found, diagnoses it and returns true. |
| 5404 | /// R is nullptr, if the caller has not (yet) done a lookup, otherwise it's |
| 5405 | /// the result of that lookup. UD is likewise nullptr, except when we have an |
| 5406 | /// already-populated UsingDecl whose shadow decls contain the same |
| 5407 | /// information (i.e. we're instantiating a UsingDecl with non-dependent |
| 5408 | /// scope). |
| 5409 | bool CheckUsingDeclQualifier(SourceLocation UsingLoc, bool HasTypename, |
| 5410 | const CXXScopeSpec &SS, |
| 5411 | const DeclarationNameInfo &NameInfo, |
| 5412 | SourceLocation NameLoc, |
| 5413 | const LookupResult *R = nullptr, |
| 5414 | const UsingDecl *UD = nullptr); |
| 5415 | |
| 5416 | /// Builds a using declaration. |
| 5417 | /// |
| 5418 | /// \param IsInstantiation - Whether this call arises from an |
| 5419 | /// instantiation of an unresolved using declaration. We treat |
| 5420 | /// the lookup differently for these declarations. |
| 5421 | NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS, |
| 5422 | SourceLocation UsingLoc, |
| 5423 | bool HasTypenameKeyword, |
| 5424 | SourceLocation TypenameLoc, CXXScopeSpec &SS, |
| 5425 | DeclarationNameInfo NameInfo, |
| 5426 | SourceLocation EllipsisLoc, |
| 5427 | const ParsedAttributesView &AttrList, |
| 5428 | bool IsInstantiation, bool IsUsingIfExists); |
| 5429 | NamedDecl *BuildUsingEnumDeclaration(Scope *S, AccessSpecifier AS, |
| 5430 | SourceLocation UsingLoc, |
| 5431 | SourceLocation EnumLoc, |
| 5432 | SourceLocation NameLoc, |
| 5433 | TypeSourceInfo *EnumType, EnumDecl *ED); |
| 5434 | NamedDecl *BuildUsingPackDecl(NamedDecl *InstantiatedFrom, |
| 5435 | ArrayRef<NamedDecl *> Expansions); |
| 5436 | |
| 5437 | /// Additional checks for a using declaration referring to a constructor name. |
| 5438 | bool CheckInheritingConstructorUsingDecl(UsingDecl *UD); |
| 5439 | |
| 5440 | /// Given a derived-class using shadow declaration for a constructor and the |
| 5441 | /// correspnding base class constructor, find or create the implicit |
| 5442 | /// synthesized derived class constructor to use for this initialization. |
| 5443 | CXXConstructorDecl * |
| 5444 | findInheritingConstructor(SourceLocation Loc, CXXConstructorDecl *BaseCtor, |
| 5445 | ConstructorUsingShadowDecl *DerivedShadow); |
| 5446 | |
| 5447 | Decl *ActOnUsingDeclaration(Scope *CurScope, AccessSpecifier AS, |
| 5448 | SourceLocation UsingLoc, |
| 5449 | SourceLocation TypenameLoc, CXXScopeSpec &SS, |
| 5450 | UnqualifiedId &Name, SourceLocation EllipsisLoc, |
| 5451 | const ParsedAttributesView &AttrList); |
| 5452 | Decl *ActOnUsingEnumDeclaration(Scope *CurScope, AccessSpecifier AS, |
| 5453 | SourceLocation UsingLoc, |
| 5454 | SourceLocation EnumLoc, SourceRange TyLoc, |
| 5455 | const IdentifierInfo &II, ParsedType Ty, |
| 5456 | const CXXScopeSpec &SS); |
| 5457 | Decl *ActOnAliasDeclaration(Scope *CurScope, AccessSpecifier AS, |
| 5458 | MultiTemplateParamsArg TemplateParams, |
| 5459 | SourceLocation UsingLoc, UnqualifiedId &Name, |
| 5460 | const ParsedAttributesView &AttrList, |
| 5461 | TypeResult Type, Decl *DeclFromDeclSpec); |
| 5462 | |
| 5463 | /// BuildCXXConstructExpr - Creates a complete call to a constructor, |
| 5464 | /// including handling of its default argument expressions. |
| 5465 | /// |
| 5466 | /// \param ConstructKind - a CXXConstructExpr::ConstructionKind |
| 5467 | ExprResult BuildCXXConstructExpr( |
| 5468 | SourceLocation ConstructLoc, QualType DeclInitType, NamedDecl *FoundDecl, |
| 5469 | CXXConstructorDecl *Constructor, MultiExprArg Exprs, |
| 5470 | bool HadMultipleCandidates, bool IsListInitialization, |
| 5471 | bool IsStdInitListInitialization, bool RequiresZeroInit, |
| 5472 | CXXConstructionKind ConstructKind, SourceRange ParenRange); |
| 5473 | |
| 5474 | /// Build a CXXConstructExpr whose constructor has already been resolved if |
| 5475 | /// it denotes an inherited constructor. |
| 5476 | ExprResult BuildCXXConstructExpr( |
| 5477 | SourceLocation ConstructLoc, QualType DeclInitType, |
| 5478 | CXXConstructorDecl *Constructor, bool Elidable, MultiExprArg Exprs, |
| 5479 | bool HadMultipleCandidates, bool IsListInitialization, |
| 5480 | bool IsStdInitListInitialization, bool RequiresZeroInit, |
| 5481 | CXXConstructionKind ConstructKind, SourceRange ParenRange); |
| 5482 | |
| 5483 | // FIXME: Can we remove this and have the above BuildCXXConstructExpr check if |
| 5484 | // the constructor can be elidable? |
| 5485 | ExprResult BuildCXXConstructExpr( |
| 5486 | SourceLocation ConstructLoc, QualType DeclInitType, NamedDecl *FoundDecl, |
| 5487 | CXXConstructorDecl *Constructor, bool Elidable, MultiExprArg Exprs, |
| 5488 | bool HadMultipleCandidates, bool IsListInitialization, |
| 5489 | bool IsStdInitListInitialization, bool RequiresZeroInit, |
| 5490 | CXXConstructionKind ConstructKind, SourceRange ParenRange); |
| 5491 | |
| 5492 | ExprResult ConvertMemberDefaultInitExpression(FieldDecl *FD, Expr *InitExpr, |
| 5493 | SourceLocation InitLoc); |
| 5494 | |
| 5495 | /// FinalizeVarWithDestructor - Prepare for calling destructor on the |
| 5496 | /// constructed variable. |
| 5497 | void FinalizeVarWithDestructor(VarDecl *VD, CXXRecordDecl *DeclInit); |
| 5498 | |
| 5499 | /// Helper class that collects exception specifications for |
| 5500 | /// implicitly-declared special member functions. |
| 5501 | class ImplicitExceptionSpecification { |
| 5502 | // Pointer to allow copying |
| 5503 | Sema *Self; |
| 5504 | // We order exception specifications thus: |
| 5505 | // noexcept is the most restrictive, but is only used in C++11. |
| 5506 | // throw() comes next. |
| 5507 | // Then a throw(collected exceptions) |
| 5508 | // Finally no specification, which is expressed as noexcept(false). |
| 5509 | // throw(...) is used instead if any called function uses it. |
| 5510 | ExceptionSpecificationType ComputedEST; |
| 5511 | llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen; |
| 5512 | SmallVector<QualType, 4> Exceptions; |
| 5513 | |
| 5514 | void ClearExceptions() { |
| 5515 | ExceptionsSeen.clear(); |
| 5516 | Exceptions.clear(); |
| 5517 | } |
| 5518 | |
| 5519 | public: |
| 5520 | explicit ImplicitExceptionSpecification(Sema &Self) |
| 5521 | : Self(&Self), ComputedEST(EST_BasicNoexcept) { |
| 5522 | if (!Self.getLangOpts().CPlusPlus11) |
| 5523 | ComputedEST = EST_DynamicNone; |
| 5524 | } |
| 5525 | |
| 5526 | /// Get the computed exception specification type. |
| 5527 | ExceptionSpecificationType getExceptionSpecType() const { |
| 5528 | assert(!isComputedNoexcept(ComputedEST) && |
| 5529 | "noexcept(expr) should not be a possible result" ); |
| 5530 | return ComputedEST; |
| 5531 | } |
| 5532 | |
| 5533 | /// The number of exceptions in the exception specification. |
| 5534 | unsigned size() const { return Exceptions.size(); } |
| 5535 | |
| 5536 | /// The set of exceptions in the exception specification. |
| 5537 | const QualType *data() const { return Exceptions.data(); } |
| 5538 | |
| 5539 | /// Integrate another called method into the collected data. |
| 5540 | void CalledDecl(SourceLocation CallLoc, const CXXMethodDecl *Method); |
| 5541 | |
| 5542 | /// Integrate an invoked expression into the collected data. |
| 5543 | void CalledExpr(Expr *E) { CalledStmt(S: E); } |
| 5544 | |
| 5545 | /// Integrate an invoked statement into the collected data. |
| 5546 | void CalledStmt(Stmt *S); |
| 5547 | |
| 5548 | /// Overwrite an EPI's exception specification with this |
| 5549 | /// computed exception specification. |
| 5550 | FunctionProtoType::ExceptionSpecInfo getExceptionSpec() const { |
| 5551 | FunctionProtoType::ExceptionSpecInfo ESI; |
| 5552 | ESI.Type = getExceptionSpecType(); |
| 5553 | if (ESI.Type == EST_Dynamic) { |
| 5554 | ESI.Exceptions = Exceptions; |
| 5555 | } else if (ESI.Type == EST_None) { |
| 5556 | /// C++11 [except.spec]p14: |
| 5557 | /// The exception-specification is noexcept(false) if the set of |
| 5558 | /// potential exceptions of the special member function contains "any" |
| 5559 | ESI.Type = EST_NoexceptFalse; |
| 5560 | ESI.NoexceptExpr = |
| 5561 | Self->ActOnCXXBoolLiteral(OpLoc: SourceLocation(), Kind: tok::kw_false).get(); |
| 5562 | } |
| 5563 | return ESI; |
| 5564 | } |
| 5565 | }; |
| 5566 | |
| 5567 | /// Evaluate the implicit exception specification for a defaulted |
| 5568 | /// special member function. |
| 5569 | void EvaluateImplicitExceptionSpec(SourceLocation Loc, FunctionDecl *FD); |
| 5570 | |
| 5571 | /// Check the given exception-specification and update the |
| 5572 | /// exception specification information with the results. |
| 5573 | void checkExceptionSpecification(bool IsTopLevel, |
| 5574 | ExceptionSpecificationType EST, |
| 5575 | ArrayRef<ParsedType> DynamicExceptions, |
| 5576 | ArrayRef<SourceRange> DynamicExceptionRanges, |
| 5577 | Expr *NoexceptExpr, |
| 5578 | SmallVectorImpl<QualType> &Exceptions, |
| 5579 | FunctionProtoType::ExceptionSpecInfo &ESI); |
| 5580 | |
| 5581 | /// Add an exception-specification to the given member or friend function |
| 5582 | /// (or function template). The exception-specification was parsed |
| 5583 | /// after the function itself was declared. |
| 5584 | void actOnDelayedExceptionSpecification( |
| 5585 | Decl *D, ExceptionSpecificationType EST, SourceRange SpecificationRange, |
| 5586 | ArrayRef<ParsedType> DynamicExceptions, |
| 5587 | ArrayRef<SourceRange> DynamicExceptionRanges, Expr *NoexceptExpr); |
| 5588 | |
| 5589 | class InheritedConstructorInfo; |
| 5590 | |
| 5591 | /// Determine if a special member function should have a deleted |
| 5592 | /// definition when it is defaulted. |
| 5593 | bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMemberKind CSM, |
| 5594 | InheritedConstructorInfo *ICI = nullptr, |
| 5595 | bool Diagnose = false); |
| 5596 | |
| 5597 | /// Produce notes explaining why a defaulted function was defined as deleted. |
| 5598 | void DiagnoseDeletedDefaultedFunction(FunctionDecl *FD); |
| 5599 | |
| 5600 | /// Declare the implicit default constructor for the given class. |
| 5601 | /// |
| 5602 | /// \param ClassDecl The class declaration into which the implicit |
| 5603 | /// default constructor will be added. |
| 5604 | /// |
| 5605 | /// \returns The implicitly-declared default constructor. |
| 5606 | CXXConstructorDecl * |
| 5607 | DeclareImplicitDefaultConstructor(CXXRecordDecl *ClassDecl); |
| 5608 | |
| 5609 | /// DefineImplicitDefaultConstructor - Checks for feasibility of |
| 5610 | /// defining this constructor as the default constructor. |
| 5611 | void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, |
| 5612 | CXXConstructorDecl *Constructor); |
| 5613 | |
| 5614 | /// Declare the implicit destructor for the given class. |
| 5615 | /// |
| 5616 | /// \param ClassDecl The class declaration into which the implicit |
| 5617 | /// destructor will be added. |
| 5618 | /// |
| 5619 | /// \returns The implicitly-declared destructor. |
| 5620 | CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); |
| 5621 | |
| 5622 | /// DefineImplicitDestructor - Checks for feasibility of |
| 5623 | /// defining this destructor as the default destructor. |
| 5624 | void DefineImplicitDestructor(SourceLocation CurrentLocation, |
| 5625 | CXXDestructorDecl *Destructor); |
| 5626 | |
| 5627 | /// Build an exception spec for destructors that don't have one. |
| 5628 | /// |
| 5629 | /// C++11 says that user-defined destructors with no exception spec get one |
| 5630 | /// that looks as if the destructor was implicitly declared. |
| 5631 | void AdjustDestructorExceptionSpec(CXXDestructorDecl *Destructor); |
| 5632 | |
| 5633 | /// Define the specified inheriting constructor. |
| 5634 | void DefineInheritingConstructor(SourceLocation UseLoc, |
| 5635 | CXXConstructorDecl *Constructor); |
| 5636 | |
| 5637 | /// Declare the implicit copy constructor for the given class. |
| 5638 | /// |
| 5639 | /// \param ClassDecl The class declaration into which the implicit |
| 5640 | /// copy constructor will be added. |
| 5641 | /// |
| 5642 | /// \returns The implicitly-declared copy constructor. |
| 5643 | CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); |
| 5644 | |
| 5645 | /// DefineImplicitCopyConstructor - Checks for feasibility of |
| 5646 | /// defining this constructor as the copy constructor. |
| 5647 | void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, |
| 5648 | CXXConstructorDecl *Constructor); |
| 5649 | |
| 5650 | /// Declare the implicit move constructor for the given class. |
| 5651 | /// |
| 5652 | /// \param ClassDecl The Class declaration into which the implicit |
| 5653 | /// move constructor will be added. |
| 5654 | /// |
| 5655 | /// \returns The implicitly-declared move constructor, or NULL if it wasn't |
| 5656 | /// declared. |
| 5657 | CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl); |
| 5658 | |
| 5659 | /// DefineImplicitMoveConstructor - Checks for feasibility of |
| 5660 | /// defining this constructor as the move constructor. |
| 5661 | void DefineImplicitMoveConstructor(SourceLocation CurrentLocation, |
| 5662 | CXXConstructorDecl *Constructor); |
| 5663 | |
| 5664 | /// Declare the implicit copy assignment operator for the given class. |
| 5665 | /// |
| 5666 | /// \param ClassDecl The class declaration into which the implicit |
| 5667 | /// copy assignment operator will be added. |
| 5668 | /// |
| 5669 | /// \returns The implicitly-declared copy assignment operator. |
| 5670 | CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); |
| 5671 | |
| 5672 | /// Defines an implicitly-declared copy assignment operator. |
| 5673 | void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, |
| 5674 | CXXMethodDecl *MethodDecl); |
| 5675 | |
| 5676 | /// Declare the implicit move assignment operator for the given class. |
| 5677 | /// |
| 5678 | /// \param ClassDecl The Class declaration into which the implicit |
| 5679 | /// move assignment operator will be added. |
| 5680 | /// |
| 5681 | /// \returns The implicitly-declared move assignment operator, or NULL if it |
| 5682 | /// wasn't declared. |
| 5683 | CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl); |
| 5684 | |
| 5685 | /// Defines an implicitly-declared move assignment operator. |
| 5686 | void DefineImplicitMoveAssignment(SourceLocation CurrentLocation, |
| 5687 | CXXMethodDecl *MethodDecl); |
| 5688 | |
| 5689 | /// Check a completed declaration of an implicit special member. |
| 5690 | void CheckImplicitSpecialMemberDeclaration(Scope *S, FunctionDecl *FD); |
| 5691 | |
| 5692 | /// Determine whether the given function is an implicitly-deleted |
| 5693 | /// special member function. |
| 5694 | bool isImplicitlyDeleted(FunctionDecl *FD); |
| 5695 | |
| 5696 | /// Check whether 'this' shows up in the type of a static member |
| 5697 | /// function after the (naturally empty) cv-qualifier-seq would be. |
| 5698 | /// |
| 5699 | /// \returns true if an error occurred. |
| 5700 | bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method); |
| 5701 | |
| 5702 | /// Whether this' shows up in the exception specification of a static |
| 5703 | /// member function. |
| 5704 | bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method); |
| 5705 | |
| 5706 | /// Check whether 'this' shows up in the attributes of the given |
| 5707 | /// static member function. |
| 5708 | /// |
| 5709 | /// \returns true if an error occurred. |
| 5710 | bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method); |
| 5711 | |
| 5712 | bool CheckImmediateEscalatingFunctionDefinition( |
| 5713 | FunctionDecl *FD, const sema::FunctionScopeInfo *FSI); |
| 5714 | |
| 5715 | void DiagnoseImmediateEscalatingReason(FunctionDecl *FD); |
| 5716 | |
| 5717 | /// Given a constructor and the set of arguments provided for the |
| 5718 | /// constructor, convert the arguments and add any required default arguments |
| 5719 | /// to form a proper call to this constructor. |
| 5720 | /// |
| 5721 | /// \returns true if an error occurred, false otherwise. |
| 5722 | bool CompleteConstructorCall(CXXConstructorDecl *Constructor, |
| 5723 | QualType DeclInitType, MultiExprArg ArgsPtr, |
| 5724 | SourceLocation Loc, |
| 5725 | SmallVectorImpl<Expr *> &ConvertedArgs, |
| 5726 | bool AllowExplicit = false, |
| 5727 | bool IsListInitialization = false); |
| 5728 | |
| 5729 | /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an |
| 5730 | /// initializer for the declaration 'Dcl'. |
| 5731 | /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a |
| 5732 | /// static data member of class X, names should be looked up in the scope of |
| 5733 | /// class X. |
| 5734 | void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl); |
| 5735 | |
| 5736 | /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an |
| 5737 | /// initializer for the declaration 'Dcl'. |
| 5738 | void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl); |
| 5739 | |
| 5740 | /// Define the "body" of the conversion from a lambda object to a |
| 5741 | /// function pointer. |
| 5742 | /// |
| 5743 | /// This routine doesn't actually define a sensible body; rather, it fills |
| 5744 | /// in the initialization expression needed to copy the lambda object into |
| 5745 | /// the block, and IR generation actually generates the real body of the |
| 5746 | /// block pointer conversion. |
| 5747 | void |
| 5748 | DefineImplicitLambdaToFunctionPointerConversion(SourceLocation CurrentLoc, |
| 5749 | CXXConversionDecl *Conv); |
| 5750 | |
| 5751 | /// Define the "body" of the conversion from a lambda object to a |
| 5752 | /// block pointer. |
| 5753 | /// |
| 5754 | /// This routine doesn't actually define a sensible body; rather, it fills |
| 5755 | /// in the initialization expression needed to copy the lambda object into |
| 5756 | /// the block, and IR generation actually generates the real body of the |
| 5757 | /// block pointer conversion. |
| 5758 | void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc, |
| 5759 | CXXConversionDecl *Conv); |
| 5760 | |
| 5761 | /// ActOnStartLinkageSpecification - Parsed the beginning of a C++ |
| 5762 | /// linkage specification, including the language and (if present) |
| 5763 | /// the '{'. ExternLoc is the location of the 'extern', Lang is the |
| 5764 | /// language string literal. LBraceLoc, if valid, provides the location of |
| 5765 | /// the '{' brace. Otherwise, this linkage specification does not |
| 5766 | /// have any braces. |
| 5767 | Decl *ActOnStartLinkageSpecification(Scope *S, SourceLocation ExternLoc, |
| 5768 | Expr *LangStr, SourceLocation LBraceLoc); |
| 5769 | |
| 5770 | /// ActOnFinishLinkageSpecification - Complete the definition of |
| 5771 | /// the C++ linkage specification LinkageSpec. If RBraceLoc is |
| 5772 | /// valid, it's the position of the closing '}' brace in a linkage |
| 5773 | /// specification that uses braces. |
| 5774 | Decl *ActOnFinishLinkageSpecification(Scope *S, Decl *LinkageSpec, |
| 5775 | SourceLocation RBraceLoc); |
| 5776 | |
| 5777 | //===--------------------------------------------------------------------===// |
| 5778 | // C++ Classes |
| 5779 | // |
| 5780 | |
| 5781 | /// Get the class that is directly named by the current context. This is the |
| 5782 | /// class for which an unqualified-id in this scope could name a constructor |
| 5783 | /// or destructor. |
| 5784 | /// |
| 5785 | /// If the scope specifier denotes a class, this will be that class. |
| 5786 | /// If the scope specifier is empty, this will be the class whose |
| 5787 | /// member-specification we are currently within. Otherwise, there |
| 5788 | /// is no such class. |
| 5789 | CXXRecordDecl *getCurrentClass(Scope *S, const CXXScopeSpec *SS); |
| 5790 | |
| 5791 | /// isCurrentClassName - Determine whether the identifier II is the |
| 5792 | /// name of the class type currently being defined. In the case of |
| 5793 | /// nested classes, this will only return true if II is the name of |
| 5794 | /// the innermost class. |
| 5795 | bool isCurrentClassName(const IdentifierInfo &II, Scope *S, |
| 5796 | const CXXScopeSpec *SS = nullptr); |
| 5797 | |
| 5798 | /// Determine whether the identifier II is a typo for the name of |
| 5799 | /// the class type currently being defined. If so, update it to the identifier |
| 5800 | /// that should have been used. |
| 5801 | bool isCurrentClassNameTypo(IdentifierInfo *&II, const CXXScopeSpec *SS); |
| 5802 | |
| 5803 | /// ActOnAccessSpecifier - Parsed an access specifier followed by a colon. |
| 5804 | bool ActOnAccessSpecifier(AccessSpecifier Access, SourceLocation ASLoc, |
| 5805 | SourceLocation ColonLoc, |
| 5806 | const ParsedAttributesView &Attrs); |
| 5807 | |
| 5808 | /// ActOnCXXMemberDeclarator - This is invoked when a C++ class member |
| 5809 | /// declarator is parsed. 'AS' is the access specifier, 'BW' specifies the |
| 5810 | /// bitfield width if there is one, 'InitExpr' specifies the initializer if |
| 5811 | /// one has been parsed, and 'InitStyle' is set if an in-class initializer is |
| 5812 | /// present (but parsing it has been deferred). |
| 5813 | NamedDecl * |
| 5814 | ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D, |
| 5815 | MultiTemplateParamsArg TemplateParameterLists, |
| 5816 | Expr *BitfieldWidth, const VirtSpecifiers &VS, |
| 5817 | InClassInitStyle InitStyle); |
| 5818 | |
| 5819 | /// Enter a new C++ default initializer scope. After calling this, the |
| 5820 | /// caller must call \ref ActOnFinishCXXInClassMemberInitializer, even if |
| 5821 | /// parsing or instantiating the initializer failed. |
| 5822 | void ActOnStartCXXInClassMemberInitializer(); |
| 5823 | |
| 5824 | /// This is invoked after parsing an in-class initializer for a |
| 5825 | /// non-static C++ class member, and after instantiating an in-class |
| 5826 | /// initializer in a class template. Such actions are deferred until the class |
| 5827 | /// is complete. |
| 5828 | void ActOnFinishCXXInClassMemberInitializer(Decl *VarDecl, |
| 5829 | SourceLocation EqualLoc, |
| 5830 | ExprResult Init); |
| 5831 | |
| 5832 | /// Handle a C++ member initializer using parentheses syntax. |
| 5833 | MemInitResult |
| 5834 | ActOnMemInitializer(Decl *ConstructorD, Scope *S, CXXScopeSpec &SS, |
| 5835 | IdentifierInfo *MemberOrBase, ParsedType TemplateTypeTy, |
| 5836 | const DeclSpec &DS, SourceLocation IdLoc, |
| 5837 | SourceLocation LParenLoc, ArrayRef<Expr *> Args, |
| 5838 | SourceLocation RParenLoc, SourceLocation EllipsisLoc); |
| 5839 | |
| 5840 | /// Handle a C++ member initializer using braced-init-list syntax. |
| 5841 | MemInitResult ActOnMemInitializer(Decl *ConstructorD, Scope *S, |
| 5842 | CXXScopeSpec &SS, |
| 5843 | IdentifierInfo *MemberOrBase, |
| 5844 | ParsedType TemplateTypeTy, |
| 5845 | const DeclSpec &DS, SourceLocation IdLoc, |
| 5846 | Expr *InitList, SourceLocation EllipsisLoc); |
| 5847 | |
| 5848 | /// Handle a C++ member initializer. |
| 5849 | MemInitResult BuildMemInitializer(Decl *ConstructorD, Scope *S, |
| 5850 | CXXScopeSpec &SS, |
| 5851 | IdentifierInfo *MemberOrBase, |
| 5852 | ParsedType TemplateTypeTy, |
| 5853 | const DeclSpec &DS, SourceLocation IdLoc, |
| 5854 | Expr *Init, SourceLocation EllipsisLoc); |
| 5855 | |
| 5856 | MemInitResult BuildMemberInitializer(ValueDecl *Member, Expr *Init, |
| 5857 | SourceLocation IdLoc); |
| 5858 | |
| 5859 | MemInitResult BuildBaseInitializer(QualType BaseType, |
| 5860 | TypeSourceInfo *BaseTInfo, Expr *Init, |
| 5861 | CXXRecordDecl *ClassDecl, |
| 5862 | SourceLocation EllipsisLoc); |
| 5863 | |
| 5864 | MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo, Expr *Init, |
| 5865 | CXXRecordDecl *ClassDecl); |
| 5866 | |
| 5867 | bool SetDelegatingInitializer(CXXConstructorDecl *Constructor, |
| 5868 | CXXCtorInitializer *Initializer); |
| 5869 | |
| 5870 | bool SetCtorInitializers(CXXConstructorDecl *Constructor, bool AnyErrors, |
| 5871 | ArrayRef<CXXCtorInitializer *> Initializers = {}); |
| 5872 | |
| 5873 | /// MarkBaseAndMemberDestructorsReferenced - Given a record decl, |
| 5874 | /// mark all the non-trivial destructors of its members and bases as |
| 5875 | /// referenced. |
| 5876 | void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, |
| 5877 | CXXRecordDecl *Record); |
| 5878 | |
| 5879 | /// Mark destructors of virtual bases of this class referenced. In the Itanium |
| 5880 | /// C++ ABI, this is done when emitting a destructor for any non-abstract |
| 5881 | /// class. In the Microsoft C++ ABI, this is done any time a class's |
| 5882 | /// destructor is referenced. |
| 5883 | void MarkVirtualBaseDestructorsReferenced( |
| 5884 | SourceLocation Location, CXXRecordDecl *ClassDecl, |
| 5885 | llvm::SmallPtrSetImpl<const CXXRecordDecl *> *DirectVirtualBases = |
| 5886 | nullptr); |
| 5887 | |
| 5888 | /// Do semantic checks to allow the complete destructor variant to be emitted |
| 5889 | /// when the destructor is defined in another translation unit. In the Itanium |
| 5890 | /// C++ ABI, destructor variants are emitted together. In the MS C++ ABI, they |
| 5891 | /// can be emitted in separate TUs. To emit the complete variant, run a subset |
| 5892 | /// of the checks performed when emitting a regular destructor. |
| 5893 | void CheckCompleteDestructorVariant(SourceLocation CurrentLocation, |
| 5894 | CXXDestructorDecl *Dtor); |
| 5895 | |
| 5896 | /// The list of classes whose vtables have been used within |
| 5897 | /// this translation unit, and the source locations at which the |
| 5898 | /// first use occurred. |
| 5899 | typedef std::pair<CXXRecordDecl *, SourceLocation> VTableUse; |
| 5900 | |
| 5901 | /// The list of vtables that are required but have not yet been |
| 5902 | /// materialized. |
| 5903 | SmallVector<VTableUse, 16> VTableUses; |
| 5904 | |
| 5905 | /// The set of classes whose vtables have been used within |
| 5906 | /// this translation unit, and a bit that will be true if the vtable is |
| 5907 | /// required to be emitted (otherwise, it should be emitted only if needed |
| 5908 | /// by code generation). |
| 5909 | llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed; |
| 5910 | |
| 5911 | /// Load any externally-stored vtable uses. |
| 5912 | void LoadExternalVTableUses(); |
| 5913 | |
| 5914 | /// Note that the vtable for the given class was used at the |
| 5915 | /// given location. |
| 5916 | void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, |
| 5917 | bool DefinitionRequired = false); |
| 5918 | |
| 5919 | /// Mark the exception specifications of all virtual member functions |
| 5920 | /// in the given class as needed. |
| 5921 | void MarkVirtualMemberExceptionSpecsNeeded(SourceLocation Loc, |
| 5922 | const CXXRecordDecl *RD); |
| 5923 | |
| 5924 | /// MarkVirtualMembersReferenced - Will mark all members of the given |
| 5925 | /// CXXRecordDecl referenced. |
| 5926 | void MarkVirtualMembersReferenced(SourceLocation Loc, const CXXRecordDecl *RD, |
| 5927 | bool ConstexprOnly = false); |
| 5928 | |
| 5929 | /// Define all of the vtables that have been used in this |
| 5930 | /// translation unit and reference any virtual members used by those |
| 5931 | /// vtables. |
| 5932 | /// |
| 5933 | /// \returns true if any work was done, false otherwise. |
| 5934 | bool DefineUsedVTables(); |
| 5935 | |
| 5936 | /// AddImplicitlyDeclaredMembersToClass - Adds any implicitly-declared |
| 5937 | /// special functions, such as the default constructor, copy |
| 5938 | /// constructor, or destructor, to the given C++ class (C++ |
| 5939 | /// [special]p1). This routine can only be executed just before the |
| 5940 | /// definition of the class is complete. |
| 5941 | void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); |
| 5942 | |
| 5943 | /// ActOnMemInitializers - Handle the member initializers for a constructor. |
| 5944 | void ActOnMemInitializers(Decl *ConstructorDecl, SourceLocation ColonLoc, |
| 5945 | ArrayRef<CXXCtorInitializer *> MemInits, |
| 5946 | bool AnyErrors); |
| 5947 | |
| 5948 | /// Check class-level dllimport/dllexport attribute. The caller must |
| 5949 | /// ensure that referenceDLLExportedClassMethods is called some point later |
| 5950 | /// when all outer classes of Class are complete. |
| 5951 | void checkClassLevelDLLAttribute(CXXRecordDecl *Class); |
| 5952 | void checkClassLevelCodeSegAttribute(CXXRecordDecl *Class); |
| 5953 | |
| 5954 | void referenceDLLExportedClassMethods(); |
| 5955 | |
| 5956 | /// Perform propagation of DLL attributes from a derived class to a |
| 5957 | /// templated base class for MS compatibility. |
| 5958 | void propagateDLLAttrToBaseClassTemplate( |
| 5959 | CXXRecordDecl *Class, Attr *ClassAttr, |
| 5960 | ClassTemplateSpecializationDecl *BaseTemplateSpec, |
| 5961 | SourceLocation BaseLoc); |
| 5962 | |
| 5963 | /// Perform semantic checks on a class definition that has been |
| 5964 | /// completing, introducing implicitly-declared members, checking for |
| 5965 | /// abstract types, etc. |
| 5966 | /// |
| 5967 | /// \param S The scope in which the class was parsed. Null if we didn't just |
| 5968 | /// parse a class definition. |
| 5969 | /// \param Record The completed class. |
| 5970 | void CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record); |
| 5971 | |
| 5972 | /// Check that the C++ class annoated with "trivial_abi" satisfies all the |
| 5973 | /// conditions that are needed for the attribute to have an effect. |
| 5974 | void checkIllFormedTrivialABIStruct(CXXRecordDecl &RD); |
| 5975 | |
| 5976 | /// Check that VTable Pointer authentication is only being set on the first |
| 5977 | /// first instantiation of the vtable |
| 5978 | void checkIncorrectVTablePointerAuthenticationAttribute(CXXRecordDecl &RD); |
| 5979 | |
| 5980 | void ActOnFinishCXXMemberSpecification(Scope *S, SourceLocation RLoc, |
| 5981 | Decl *TagDecl, SourceLocation LBrac, |
| 5982 | SourceLocation RBrac, |
| 5983 | const ParsedAttributesView &AttrList); |
| 5984 | |
| 5985 | /// Perform any semantic analysis which needs to be delayed until all |
| 5986 | /// pending class member declarations have been parsed. |
| 5987 | void ActOnFinishCXXMemberDecls(); |
| 5988 | void ActOnFinishCXXNonNestedClass(); |
| 5989 | |
| 5990 | /// This is used to implement the constant expression evaluation part of the |
| 5991 | /// attribute enable_if extension. There is nothing in standard C++ which |
| 5992 | /// would require reentering parameters. |
| 5993 | void ActOnReenterCXXMethodParameter(Scope *S, ParmVarDecl *Param); |
| 5994 | unsigned ActOnReenterTemplateScope(Decl *Template, |
| 5995 | llvm::function_ref<Scope *()> EnterScope); |
| 5996 | void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); |
| 5997 | |
| 5998 | /// ActOnStartDelayedCXXMethodDeclaration - We have completed |
| 5999 | /// parsing a top-level (non-nested) C++ class, and we are now |
| 6000 | /// parsing those parts of the given Method declaration that could |
| 6001 | /// not be parsed earlier (C++ [class.mem]p2), such as default |
| 6002 | /// arguments. This action should enter the scope of the given |
| 6003 | /// Method declaration as if we had just parsed the qualified method |
| 6004 | /// name. However, it should not bring the parameters into scope; |
| 6005 | /// that will be performed by ActOnDelayedCXXMethodParameter. |
| 6006 | void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); |
| 6007 | void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); |
| 6008 | void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); |
| 6009 | |
| 6010 | /// ActOnFinishDelayedCXXMethodDeclaration - We have finished |
| 6011 | /// processing the delayed method declaration for Method. The method |
| 6012 | /// declaration is now considered finished. There may be a separate |
| 6013 | /// ActOnStartOfFunctionDef action later (not necessarily |
| 6014 | /// immediately!) for this method, if it was also defined inside the |
| 6015 | /// class body. |
| 6016 | void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); |
| 6017 | void ActOnFinishDelayedMemberInitializers(Decl *Record); |
| 6018 | |
| 6019 | enum class StringEvaluationContext { StaticAssert = 0, Asm = 1 }; |
| 6020 | |
| 6021 | bool EvaluateAsString(Expr *Message, APValue &Result, ASTContext &Ctx, |
| 6022 | StringEvaluationContext EvalContext, |
| 6023 | bool ErrorOnInvalidMessage); |
| 6024 | bool EvaluateAsString(Expr *Message, std::string &Result, ASTContext &Ctx, |
| 6025 | StringEvaluationContext EvalContext, |
| 6026 | bool ErrorOnInvalidMessage); |
| 6027 | |
| 6028 | Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, |
| 6029 | Expr *AssertExpr, Expr *AssertMessageExpr, |
| 6030 | SourceLocation RParenLoc); |
| 6031 | Decl *BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc, |
| 6032 | Expr *AssertExpr, Expr *AssertMessageExpr, |
| 6033 | SourceLocation RParenLoc, bool Failed); |
| 6034 | |
| 6035 | /// Try to print more useful information about a failed static_assert |
| 6036 | /// with expression \E |
| 6037 | void DiagnoseStaticAssertDetails(const Expr *E); |
| 6038 | |
| 6039 | /// If E represents a built-in type trait, or a known standard type trait, |
| 6040 | /// try to print more information about why the type type-trait failed. |
| 6041 | /// This assumes we already evaluated the expression to a false boolean value. |
| 6042 | void DiagnoseTypeTraitDetails(const Expr *E); |
| 6043 | |
| 6044 | /// Handle a friend type declaration. This works in tandem with |
| 6045 | /// ActOnTag. |
| 6046 | /// |
| 6047 | /// Notes on friend class templates: |
| 6048 | /// |
| 6049 | /// We generally treat friend class declarations as if they were |
| 6050 | /// declaring a class. So, for example, the elaborated type specifier |
| 6051 | /// in a friend declaration is required to obey the restrictions of a |
| 6052 | /// class-head (i.e. no typedefs in the scope chain), template |
| 6053 | /// parameters are required to match up with simple template-ids, &c. |
| 6054 | /// However, unlike when declaring a template specialization, it's |
| 6055 | /// okay to refer to a template specialization without an empty |
| 6056 | /// template parameter declaration, e.g. |
| 6057 | /// friend class A<T>::B<unsigned>; |
| 6058 | /// We permit this as a special case; if there are any template |
| 6059 | /// parameters present at all, require proper matching, i.e. |
| 6060 | /// template <> template \<class T> friend class A<int>::B; |
| 6061 | Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, |
| 6062 | MultiTemplateParamsArg TemplateParams, |
| 6063 | SourceLocation EllipsisLoc); |
| 6064 | NamedDecl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, |
| 6065 | MultiTemplateParamsArg TemplateParams); |
| 6066 | |
| 6067 | /// CheckConstructorDeclarator - Called by ActOnDeclarator to check |
| 6068 | /// the well-formedness of the constructor declarator @p D with type @p |
| 6069 | /// R. If there are any errors in the declarator, this routine will |
| 6070 | /// emit diagnostics and set the invalid bit to true. In any case, the type |
| 6071 | /// will be updated to reflect a well-formed type for the constructor and |
| 6072 | /// returned. |
| 6073 | QualType CheckConstructorDeclarator(Declarator &D, QualType R, |
| 6074 | StorageClass &SC); |
| 6075 | |
| 6076 | /// CheckConstructor - Checks a fully-formed constructor for |
| 6077 | /// well-formedness, issuing any diagnostics required. Returns true if |
| 6078 | /// the constructor declarator is invalid. |
| 6079 | void CheckConstructor(CXXConstructorDecl *Constructor); |
| 6080 | |
| 6081 | /// CheckDestructorDeclarator - Called by ActOnDeclarator to check |
| 6082 | /// the well-formednes of the destructor declarator @p D with type @p |
| 6083 | /// R. If there are any errors in the declarator, this routine will |
| 6084 | /// emit diagnostics and set the declarator to invalid. Even if this happens, |
| 6085 | /// will be updated to reflect a well-formed type for the destructor and |
| 6086 | /// returned. |
| 6087 | QualType CheckDestructorDeclarator(Declarator &D, QualType R, |
| 6088 | StorageClass &SC); |
| 6089 | |
| 6090 | /// CheckDestructor - Checks a fully-formed destructor definition for |
| 6091 | /// well-formedness, issuing any diagnostics required. Returns true |
| 6092 | /// on error. |
| 6093 | bool CheckDestructor(CXXDestructorDecl *Destructor); |
| 6094 | |
| 6095 | /// CheckConversionDeclarator - Called by ActOnDeclarator to check the |
| 6096 | /// well-formednes of the conversion function declarator @p D with |
| 6097 | /// type @p R. If there are any errors in the declarator, this routine |
| 6098 | /// will emit diagnostics and return true. Otherwise, it will return |
| 6099 | /// false. Either way, the type @p R will be updated to reflect a |
| 6100 | /// well-formed type for the conversion operator. |
| 6101 | void CheckConversionDeclarator(Declarator &D, QualType &R, StorageClass &SC); |
| 6102 | |
| 6103 | /// ActOnConversionDeclarator - Called by ActOnDeclarator to complete |
| 6104 | /// the declaration of the given C++ conversion function. This routine |
| 6105 | /// is responsible for recording the conversion function in the C++ |
| 6106 | /// class, if possible. |
| 6107 | Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); |
| 6108 | |
| 6109 | /// Check the validity of a declarator that we parsed for a deduction-guide. |
| 6110 | /// These aren't actually declarators in the grammar, so we need to check that |
| 6111 | /// the user didn't specify any pieces that are not part of the |
| 6112 | /// deduction-guide grammar. Return true on invalid deduction-guide. |
| 6113 | bool CheckDeductionGuideDeclarator(Declarator &D, QualType &R, |
| 6114 | StorageClass &SC); |
| 6115 | |
| 6116 | void CheckExplicitlyDefaultedFunction(Scope *S, FunctionDecl *MD); |
| 6117 | |
| 6118 | bool CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD, |
| 6119 | CXXSpecialMemberKind CSM, |
| 6120 | SourceLocation DefaultLoc); |
| 6121 | void CheckDelayedMemberExceptionSpecs(); |
| 6122 | |
| 6123 | /// Kinds of defaulted comparison operator functions. |
| 6124 | enum class DefaultedComparisonKind : unsigned char { |
| 6125 | /// This is not a defaultable comparison operator. |
| 6126 | None, |
| 6127 | /// This is an operator== that should be implemented as a series of |
| 6128 | /// subobject comparisons. |
| 6129 | Equal, |
| 6130 | /// This is an operator<=> that should be implemented as a series of |
| 6131 | /// subobject comparisons. |
| 6132 | ThreeWay, |
| 6133 | /// This is an operator!= that should be implemented as a rewrite in terms |
| 6134 | /// of a == comparison. |
| 6135 | NotEqual, |
| 6136 | /// This is an <, <=, >, or >= that should be implemented as a rewrite in |
| 6137 | /// terms of a <=> comparison. |
| 6138 | Relational, |
| 6139 | }; |
| 6140 | |
| 6141 | bool CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *MD, |
| 6142 | DefaultedComparisonKind DCK); |
| 6143 | void DeclareImplicitEqualityComparison(CXXRecordDecl *RD, |
| 6144 | FunctionDecl *Spaceship); |
| 6145 | void DefineDefaultedComparison(SourceLocation Loc, FunctionDecl *FD, |
| 6146 | DefaultedComparisonKind DCK); |
| 6147 | |
| 6148 | void CheckExplicitObjectMemberFunction(Declarator &D, DeclarationName Name, |
| 6149 | QualType R, bool IsLambda, |
| 6150 | DeclContext *DC = nullptr); |
| 6151 | void CheckExplicitObjectMemberFunction(DeclContext *DC, Declarator &D, |
| 6152 | DeclarationName Name, QualType R); |
| 6153 | void CheckExplicitObjectLambda(Declarator &D); |
| 6154 | |
| 6155 | //===--------------------------------------------------------------------===// |
| 6156 | // C++ Derived Classes |
| 6157 | // |
| 6158 | |
| 6159 | /// Check the validity of a C++ base class specifier. |
| 6160 | /// |
| 6161 | /// \returns a new CXXBaseSpecifier if well-formed, emits diagnostics |
| 6162 | /// and returns NULL otherwise. |
| 6163 | CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, |
| 6164 | SourceRange SpecifierRange, bool Virtual, |
| 6165 | AccessSpecifier Access, |
| 6166 | TypeSourceInfo *TInfo, |
| 6167 | SourceLocation EllipsisLoc); |
| 6168 | |
| 6169 | /// ActOnBaseSpecifier - Parsed a base specifier. A base specifier is |
| 6170 | /// one entry in the base class list of a class specifier, for |
| 6171 | /// example: |
| 6172 | /// class foo : public bar, virtual private baz { |
| 6173 | /// 'public bar' and 'virtual private baz' are each base-specifiers. |
| 6174 | BaseResult ActOnBaseSpecifier(Decl *classdecl, SourceRange SpecifierRange, |
| 6175 | const ParsedAttributesView &Attrs, bool Virtual, |
| 6176 | AccessSpecifier Access, ParsedType basetype, |
| 6177 | SourceLocation BaseLoc, |
| 6178 | SourceLocation EllipsisLoc); |
| 6179 | |
| 6180 | /// Performs the actual work of attaching the given base class |
| 6181 | /// specifiers to a C++ class. |
| 6182 | bool AttachBaseSpecifiers(CXXRecordDecl *Class, |
| 6183 | MutableArrayRef<CXXBaseSpecifier *> Bases); |
| 6184 | |
| 6185 | /// ActOnBaseSpecifiers - Attach the given base specifiers to the |
| 6186 | /// class, after checking whether there are any duplicate base |
| 6187 | /// classes. |
| 6188 | void ActOnBaseSpecifiers(Decl *ClassDecl, |
| 6189 | MutableArrayRef<CXXBaseSpecifier *> Bases); |
| 6190 | |
| 6191 | /// Determine whether the type \p Derived is a C++ class that is |
| 6192 | /// derived from the type \p Base. |
| 6193 | bool IsDerivedFrom(SourceLocation Loc, CXXRecordDecl *Derived, |
| 6194 | CXXRecordDecl *Base, CXXBasePaths &Paths); |
| 6195 | bool IsDerivedFrom(SourceLocation Loc, CXXRecordDecl *Derived, |
| 6196 | CXXRecordDecl *Base); |
| 6197 | bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base); |
| 6198 | bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base, |
| 6199 | CXXBasePaths &Paths); |
| 6200 | |
| 6201 | // FIXME: I don't like this name. |
| 6202 | void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); |
| 6203 | |
| 6204 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
| 6205 | SourceLocation Loc, SourceRange Range, |
| 6206 | CXXCastPath *BasePath = nullptr, |
| 6207 | bool IgnoreAccess = false); |
| 6208 | |
| 6209 | /// CheckDerivedToBaseConversion - Check whether the Derived-to-Base |
| 6210 | /// conversion (where Derived and Base are class types) is |
| 6211 | /// well-formed, meaning that the conversion is unambiguous (and |
| 6212 | /// that all of the base classes are accessible). Returns true |
| 6213 | /// and emits a diagnostic if the code is ill-formed, returns false |
| 6214 | /// otherwise. Loc is the location where this routine should point to |
| 6215 | /// if there is an error, and Range is the source range to highlight |
| 6216 | /// if there is an error. |
| 6217 | /// |
| 6218 | /// If either InaccessibleBaseID or AmbiguousBaseConvID are 0, then the |
| 6219 | /// diagnostic for the respective type of error will be suppressed, but the |
| 6220 | /// check for ill-formed code will still be performed. |
| 6221 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
| 6222 | unsigned InaccessibleBaseID, |
| 6223 | unsigned AmbiguousBaseConvID, |
| 6224 | SourceLocation Loc, SourceRange Range, |
| 6225 | DeclarationName Name, CXXCastPath *BasePath, |
| 6226 | bool IgnoreAccess = false); |
| 6227 | |
| 6228 | /// Builds a string representing ambiguous paths from a |
| 6229 | /// specific derived class to different subobjects of the same base |
| 6230 | /// class. |
| 6231 | /// |
| 6232 | /// This function builds a string that can be used in error messages |
| 6233 | /// to show the different paths that one can take through the |
| 6234 | /// inheritance hierarchy to go from the derived class to different |
| 6235 | /// subobjects of a base class. The result looks something like this: |
| 6236 | /// @code |
| 6237 | /// struct D -> struct B -> struct A |
| 6238 | /// struct D -> struct C -> struct A |
| 6239 | /// @endcode |
| 6240 | std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); |
| 6241 | |
| 6242 | bool CheckOverridingFunctionAttributes(CXXMethodDecl *New, |
| 6243 | const CXXMethodDecl *Old); |
| 6244 | |
| 6245 | /// CheckOverridingFunctionReturnType - Checks whether the return types are |
| 6246 | /// covariant, according to C++ [class.virtual]p5. |
| 6247 | bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, |
| 6248 | const CXXMethodDecl *Old); |
| 6249 | |
| 6250 | // Check that the overriding method has no explicit object parameter. |
| 6251 | bool CheckExplicitObjectOverride(CXXMethodDecl *New, |
| 6252 | const CXXMethodDecl *Old); |
| 6253 | |
| 6254 | /// Mark the given method pure. |
| 6255 | /// |
| 6256 | /// \param Method the method to be marked pure. |
| 6257 | /// |
| 6258 | /// \param InitRange the source range that covers the "0" initializer. |
| 6259 | bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); |
| 6260 | |
| 6261 | /// CheckOverrideControl - Check C++11 override control semantics. |
| 6262 | void CheckOverrideControl(NamedDecl *D); |
| 6263 | |
| 6264 | /// DiagnoseAbsenceOfOverrideControl - Diagnose if 'override' keyword was |
| 6265 | /// not used in the declaration of an overriding method. |
| 6266 | void DiagnoseAbsenceOfOverrideControl(NamedDecl *D, bool Inconsistent); |
| 6267 | |
| 6268 | /// CheckIfOverriddenFunctionIsMarkedFinal - Checks whether a virtual member |
| 6269 | /// function overrides a virtual member function marked 'final', according to |
| 6270 | /// C++11 [class.virtual]p4. |
| 6271 | bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, |
| 6272 | const CXXMethodDecl *Old); |
| 6273 | |
| 6274 | enum AbstractDiagSelID { |
| 6275 | AbstractNone = -1, |
| 6276 | AbstractReturnType, |
| 6277 | AbstractParamType, |
| 6278 | AbstractVariableType, |
| 6279 | AbstractFieldType, |
| 6280 | AbstractIvarType, |
| 6281 | AbstractSynthesizedIvarType, |
| 6282 | AbstractArrayType |
| 6283 | }; |
| 6284 | |
| 6285 | struct TypeDiagnoser; |
| 6286 | |
| 6287 | bool isAbstractType(SourceLocation Loc, QualType T); |
| 6288 | bool RequireNonAbstractType(SourceLocation Loc, QualType T, |
| 6289 | TypeDiagnoser &Diagnoser); |
| 6290 | template <typename... Ts> |
| 6291 | bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, |
| 6292 | const Ts &...Args) { |
| 6293 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
| 6294 | return RequireNonAbstractType(Loc, T, Diagnoser); |
| 6295 | } |
| 6296 | |
| 6297 | void DiagnoseAbstractType(const CXXRecordDecl *RD); |
| 6298 | |
| 6299 | //===--------------------------------------------------------------------===// |
| 6300 | // C++ Overloaded Operators [C++ 13.5] |
| 6301 | // |
| 6302 | |
| 6303 | /// CheckOverloadedOperatorDeclaration - Check whether the declaration |
| 6304 | /// of this overloaded operator is well-formed. If so, returns false; |
| 6305 | /// otherwise, emits appropriate diagnostics and returns true. |
| 6306 | bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); |
| 6307 | |
| 6308 | /// CheckLiteralOperatorDeclaration - Check whether the declaration |
| 6309 | /// of this literal operator function is well-formed. If so, returns |
| 6310 | /// false; otherwise, emits appropriate diagnostics and returns true. |
| 6311 | bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); |
| 6312 | |
| 6313 | /// ActOnExplicitBoolSpecifier - Build an ExplicitSpecifier from an expression |
| 6314 | /// found in an explicit(bool) specifier. |
| 6315 | ExplicitSpecifier ActOnExplicitBoolSpecifier(Expr *E); |
| 6316 | |
| 6317 | /// tryResolveExplicitSpecifier - Attempt to resolve the explict specifier. |
| 6318 | /// Returns true if the explicit specifier is now resolved. |
| 6319 | bool tryResolveExplicitSpecifier(ExplicitSpecifier &ExplicitSpec); |
| 6320 | |
| 6321 | /// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a |
| 6322 | /// C++ if/switch/while/for statement. |
| 6323 | /// e.g: "if (int x = f()) {...}" |
| 6324 | DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D); |
| 6325 | |
| 6326 | // Emitting members of dllexported classes is delayed until the class |
| 6327 | // (including field initializers) is fully parsed. |
| 6328 | SmallVector<CXXRecordDecl *, 4> DelayedDllExportClasses; |
| 6329 | SmallVector<CXXMethodDecl *, 4> DelayedDllExportMemberFunctions; |
| 6330 | |
| 6331 | /// Merge the exception specifications of two variable declarations. |
| 6332 | /// |
| 6333 | /// This is called when there's a redeclaration of a VarDecl. The function |
| 6334 | /// checks if the redeclaration might have an exception specification and |
| 6335 | /// validates compatibility and merges the specs if necessary. |
| 6336 | void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old); |
| 6337 | |
| 6338 | /// MergeCXXFunctionDecl - Merge two declarations of the same C++ |
| 6339 | /// function, once we already know that they have the same |
| 6340 | /// type. Subroutine of MergeFunctionDecl. Returns true if there was an |
| 6341 | /// error, false otherwise. |
| 6342 | bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S); |
| 6343 | |
| 6344 | /// Helpers for dealing with blocks and functions. |
| 6345 | void CheckCXXDefaultArguments(FunctionDecl *FD); |
| 6346 | |
| 6347 | /// CheckExtraCXXDefaultArguments - Check for any extra default |
| 6348 | /// arguments in the declarator, which is not a function declaration |
| 6349 | /// or definition and therefore is not permitted to have default |
| 6350 | /// arguments. This routine should be invoked for every declarator |
| 6351 | /// that is not a function declaration or definition. |
| 6352 | void (Declarator &D); |
| 6353 | |
| 6354 | CXXSpecialMemberKind getSpecialMember(const CXXMethodDecl *MD) { |
| 6355 | return getDefaultedFunctionKind(FD: MD).asSpecialMember(); |
| 6356 | } |
| 6357 | |
| 6358 | /// Perform semantic analysis for the variable declaration that |
| 6359 | /// occurs within a C++ catch clause, returning the newly-created |
| 6360 | /// variable. |
| 6361 | VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, |
| 6362 | SourceLocation StartLoc, |
| 6363 | SourceLocation IdLoc, |
| 6364 | const IdentifierInfo *Id); |
| 6365 | |
| 6366 | /// ActOnExceptionDeclarator - Parsed the exception-declarator in a C++ catch |
| 6367 | /// handler. |
| 6368 | Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D); |
| 6369 | |
| 6370 | void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock); |
| 6371 | |
| 6372 | /// Handle a friend tag declaration where the scope specifier was |
| 6373 | /// templated. |
| 6374 | DeclResult ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, |
| 6375 | unsigned TagSpec, SourceLocation TagLoc, |
| 6376 | CXXScopeSpec &SS, IdentifierInfo *Name, |
| 6377 | SourceLocation NameLoc, |
| 6378 | SourceLocation EllipsisLoc, |
| 6379 | const ParsedAttributesView &Attr, |
| 6380 | MultiTemplateParamsArg TempParamLists); |
| 6381 | |
| 6382 | MSPropertyDecl *HandleMSProperty(Scope *S, RecordDecl *TagD, |
| 6383 | SourceLocation DeclStart, Declarator &D, |
| 6384 | Expr *BitfieldWidth, |
| 6385 | InClassInitStyle InitStyle, |
| 6386 | AccessSpecifier AS, |
| 6387 | const ParsedAttr &MSPropertyAttr); |
| 6388 | |
| 6389 | /// Diagnose why the specified class does not have a trivial special member of |
| 6390 | /// the given kind. |
| 6391 | void DiagnoseNontrivial(const CXXRecordDecl *Record, |
| 6392 | CXXSpecialMemberKind CSM); |
| 6393 | |
| 6394 | /// Determine whether a defaulted or deleted special member function is |
| 6395 | /// trivial, as specified in C++11 [class.ctor]p5, C++11 [class.copy]p12, |
| 6396 | /// C++11 [class.copy]p25, and C++11 [class.dtor]p5. |
| 6397 | bool SpecialMemberIsTrivial( |
| 6398 | CXXMethodDecl *MD, CXXSpecialMemberKind CSM, |
| 6399 | TrivialABIHandling TAH = TrivialABIHandling::IgnoreTrivialABI, |
| 6400 | bool Diagnose = false); |
| 6401 | |
| 6402 | /// For a defaulted function, the kind of defaulted function that it is. |
| 6403 | class DefaultedFunctionKind { |
| 6404 | LLVM_PREFERRED_TYPE(CXXSpecialMemberKind) |
| 6405 | unsigned SpecialMember : 8; |
| 6406 | unsigned Comparison : 8; |
| 6407 | |
| 6408 | public: |
| 6409 | DefaultedFunctionKind() |
| 6410 | : SpecialMember(llvm::to_underlying(E: CXXSpecialMemberKind::Invalid)), |
| 6411 | Comparison(llvm::to_underlying(E: DefaultedComparisonKind::None)) {} |
| 6412 | DefaultedFunctionKind(CXXSpecialMemberKind CSM) |
| 6413 | : SpecialMember(llvm::to_underlying(E: CSM)), |
| 6414 | Comparison(llvm::to_underlying(E: DefaultedComparisonKind::None)) {} |
| 6415 | DefaultedFunctionKind(DefaultedComparisonKind Comp) |
| 6416 | : SpecialMember(llvm::to_underlying(E: CXXSpecialMemberKind::Invalid)), |
| 6417 | Comparison(llvm::to_underlying(E: Comp)) {} |
| 6418 | |
| 6419 | bool isSpecialMember() const { |
| 6420 | return static_cast<CXXSpecialMemberKind>(SpecialMember) != |
| 6421 | CXXSpecialMemberKind::Invalid; |
| 6422 | } |
| 6423 | bool isComparison() const { |
| 6424 | return static_cast<DefaultedComparisonKind>(Comparison) != |
| 6425 | DefaultedComparisonKind::None; |
| 6426 | } |
| 6427 | |
| 6428 | explicit operator bool() const { |
| 6429 | return isSpecialMember() || isComparison(); |
| 6430 | } |
| 6431 | |
| 6432 | CXXSpecialMemberKind asSpecialMember() const { |
| 6433 | return static_cast<CXXSpecialMemberKind>(SpecialMember); |
| 6434 | } |
| 6435 | DefaultedComparisonKind asComparison() const { |
| 6436 | return static_cast<DefaultedComparisonKind>(Comparison); |
| 6437 | } |
| 6438 | |
| 6439 | /// Get the index of this function kind for use in diagnostics. |
| 6440 | unsigned getDiagnosticIndex() const { |
| 6441 | static_assert(llvm::to_underlying(E: CXXSpecialMemberKind::Invalid) > |
| 6442 | llvm::to_underlying(E: CXXSpecialMemberKind::Destructor), |
| 6443 | "invalid should have highest index" ); |
| 6444 | static_assert((unsigned)DefaultedComparisonKind::None == 0, |
| 6445 | "none should be equal to zero" ); |
| 6446 | return SpecialMember + Comparison; |
| 6447 | } |
| 6448 | }; |
| 6449 | |
| 6450 | /// Determine the kind of defaulting that would be done for a given function. |
| 6451 | /// |
| 6452 | /// If the function is both a default constructor and a copy / move |
| 6453 | /// constructor (due to having a default argument for the first parameter), |
| 6454 | /// this picks CXXSpecialMemberKind::DefaultConstructor. |
| 6455 | /// |
| 6456 | /// FIXME: Check that case is properly handled by all callers. |
| 6457 | DefaultedFunctionKind getDefaultedFunctionKind(const FunctionDecl *FD); |
| 6458 | |
| 6459 | /// Handle a C++11 empty-declaration and attribute-declaration. |
| 6460 | Decl *ActOnEmptyDeclaration(Scope *S, const ParsedAttributesView &AttrList, |
| 6461 | SourceLocation SemiLoc); |
| 6462 | |
| 6463 | enum class CheckConstexprKind { |
| 6464 | /// Diagnose issues that are non-constant or that are extensions. |
| 6465 | Diagnose, |
| 6466 | /// Identify whether this function satisfies the formal rules for constexpr |
| 6467 | /// functions in the current lanugage mode (with no extensions). |
| 6468 | CheckValid |
| 6469 | }; |
| 6470 | |
| 6471 | // Check whether a function declaration satisfies the requirements of a |
| 6472 | // constexpr function definition or a constexpr constructor definition. If so, |
| 6473 | // return true. If not, produce appropriate diagnostics (unless asked not to |
| 6474 | // by Kind) and return false. |
| 6475 | // |
| 6476 | // This implements C++11 [dcl.constexpr]p3,4, as amended by DR1360. |
| 6477 | bool CheckConstexprFunctionDefinition(const FunctionDecl *FD, |
| 6478 | CheckConstexprKind Kind); |
| 6479 | |
| 6480 | /// Diagnose methods which overload virtual methods in a base class |
| 6481 | /// without overriding any. |
| 6482 | void DiagnoseHiddenVirtualMethods(CXXMethodDecl *MD); |
| 6483 | |
| 6484 | /// Check if a method overloads virtual methods in a base class without |
| 6485 | /// overriding any. |
| 6486 | void |
| 6487 | FindHiddenVirtualMethods(CXXMethodDecl *MD, |
| 6488 | SmallVectorImpl<CXXMethodDecl *> &OverloadedMethods); |
| 6489 | void |
| 6490 | NoteHiddenVirtualMethods(CXXMethodDecl *MD, |
| 6491 | SmallVectorImpl<CXXMethodDecl *> &OverloadedMethods); |
| 6492 | |
| 6493 | /// ActOnParamDefaultArgument - Check whether the default argument |
| 6494 | /// provided for a function parameter is well-formed. If so, attach it |
| 6495 | /// to the parameter declaration. |
| 6496 | void ActOnParamDefaultArgument(Decl *param, SourceLocation EqualLoc, |
| 6497 | Expr *defarg); |
| 6498 | |
| 6499 | /// ActOnParamUnparsedDefaultArgument - We've seen a default |
| 6500 | /// argument for a function parameter, but we can't parse it yet |
| 6501 | /// because we're inside a class definition. Note that this default |
| 6502 | /// argument will be parsed later. |
| 6503 | void ActOnParamUnparsedDefaultArgument(Decl *param, SourceLocation EqualLoc, |
| 6504 | SourceLocation ArgLoc); |
| 6505 | |
| 6506 | /// ActOnParamDefaultArgumentError - Parsing or semantic analysis of |
| 6507 | /// the default argument for the parameter param failed. |
| 6508 | void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc, |
| 6509 | Expr *DefaultArg); |
| 6510 | ExprResult ConvertParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, |
| 6511 | SourceLocation EqualLoc); |
| 6512 | void SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, |
| 6513 | SourceLocation EqualLoc); |
| 6514 | |
| 6515 | void ActOnPureSpecifier(Decl *D, SourceLocation PureSpecLoc); |
| 6516 | void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc, |
| 6517 | StringLiteral *Message = nullptr); |
| 6518 | void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc); |
| 6519 | |
| 6520 | void SetFunctionBodyKind(Decl *D, SourceLocation Loc, FnBodyKind BodyKind, |
| 6521 | StringLiteral *DeletedMessage = nullptr); |
| 6522 | void ActOnStartTrailingRequiresClause(Scope *S, Declarator &D); |
| 6523 | ExprResult ActOnFinishTrailingRequiresClause(ExprResult ConstraintExpr); |
| 6524 | ExprResult ActOnRequiresClause(ExprResult ConstraintExpr); |
| 6525 | |
| 6526 | NamedDecl * |
| 6527 | ActOnDecompositionDeclarator(Scope *S, Declarator &D, |
| 6528 | MultiTemplateParamsArg TemplateParamLists); |
| 6529 | void DiagPlaceholderVariableDefinition(SourceLocation Loc); |
| 6530 | bool DiagRedefinedPlaceholderFieldDecl(SourceLocation Loc, |
| 6531 | RecordDecl *ClassDecl, |
| 6532 | const IdentifierInfo *Name); |
| 6533 | |
| 6534 | UnsignedOrNone GetDecompositionElementCount(QualType DecompType, |
| 6535 | SourceLocation Loc); |
| 6536 | void CheckCompleteDecompositionDeclaration(DecompositionDecl *DD); |
| 6537 | |
| 6538 | /// Stack containing information needed when in C++2a an 'auto' is encountered |
| 6539 | /// in a function declaration parameter type specifier in order to invent a |
| 6540 | /// corresponding template parameter in the enclosing abbreviated function |
| 6541 | /// template. This information is also present in LambdaScopeInfo, stored in |
| 6542 | /// the FunctionScopes stack. |
| 6543 | SmallVector<InventedTemplateParameterInfo, 4> InventedParameterInfos; |
| 6544 | |
| 6545 | /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes. |
| 6546 | std::unique_ptr<CXXFieldCollector> FieldCollector; |
| 6547 | |
| 6548 | typedef llvm::SmallSetVector<const NamedDecl *, 16> NamedDeclSetType; |
| 6549 | /// Set containing all declared private fields that are not used. |
| 6550 | NamedDeclSetType UnusedPrivateFields; |
| 6551 | |
| 6552 | typedef llvm::SmallPtrSet<const CXXRecordDecl *, 8> RecordDeclSetTy; |
| 6553 | |
| 6554 | /// PureVirtualClassDiagSet - a set of class declarations which we have |
| 6555 | /// emitted a list of pure virtual functions. Used to prevent emitting the |
| 6556 | /// same list more than once. |
| 6557 | std::unique_ptr<RecordDeclSetTy> PureVirtualClassDiagSet; |
| 6558 | |
| 6559 | typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource, |
| 6560 | &ExternalSemaSource::ReadDelegatingConstructors, 2, 2> |
| 6561 | DelegatingCtorDeclsType; |
| 6562 | |
| 6563 | /// All the delegating constructors seen so far in the file, used for |
| 6564 | /// cycle detection at the end of the TU. |
| 6565 | DelegatingCtorDeclsType DelegatingCtorDecls; |
| 6566 | |
| 6567 | /// The C++ "std" namespace, where the standard library resides. |
| 6568 | LazyDeclPtr StdNamespace; |
| 6569 | |
| 6570 | /// The C++ "std::initializer_list" template, which is defined in |
| 6571 | /// \<initializer_list>. |
| 6572 | ClassTemplateDecl *StdInitializerList; |
| 6573 | |
| 6574 | /// The C++ "std::type_identity" template, which is defined in |
| 6575 | /// \<type_traits>. |
| 6576 | ClassTemplateDecl *StdTypeIdentity; |
| 6577 | |
| 6578 | // Contains the locations of the beginning of unparsed default |
| 6579 | // argument locations. |
| 6580 | llvm::DenseMap<ParmVarDecl *, SourceLocation> UnparsedDefaultArgLocs; |
| 6581 | |
| 6582 | /// UndefinedInternals - all the used, undefined objects which require a |
| 6583 | /// definition in this translation unit. |
| 6584 | llvm::MapVector<NamedDecl *, SourceLocation> UndefinedButUsed; |
| 6585 | |
| 6586 | typedef llvm::PointerIntPair<CXXRecordDecl *, 3, CXXSpecialMemberKind> |
| 6587 | SpecialMemberDecl; |
| 6588 | |
| 6589 | /// The C++ special members which we are currently in the process of |
| 6590 | /// declaring. If this process recursively triggers the declaration of the |
| 6591 | /// same special member, we should act as if it is not yet declared. |
| 6592 | llvm::SmallPtrSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared; |
| 6593 | |
| 6594 | void NoteDeletedInheritingConstructor(CXXConstructorDecl *CD); |
| 6595 | |
| 6596 | void ActOnDefaultCtorInitializers(Decl *CDtorDecl); |
| 6597 | |
| 6598 | typedef ProcessingContextState ParsingClassState; |
| 6599 | ParsingClassState PushParsingClass() { |
| 6600 | ParsingClassDepth++; |
| 6601 | return DelayedDiagnostics.pushUndelayed(); |
| 6602 | } |
| 6603 | void PopParsingClass(ParsingClassState state) { |
| 6604 | ParsingClassDepth--; |
| 6605 | DelayedDiagnostics.popUndelayed(state); |
| 6606 | } |
| 6607 | |
| 6608 | ValueDecl *tryLookupCtorInitMemberDecl(CXXRecordDecl *ClassDecl, |
| 6609 | CXXScopeSpec &SS, |
| 6610 | ParsedType TemplateTypeTy, |
| 6611 | IdentifierInfo *MemberOrBase); |
| 6612 | |
| 6613 | private: |
| 6614 | void setupImplicitSpecialMemberType(CXXMethodDecl *SpecialMem, |
| 6615 | QualType ResultTy, |
| 6616 | ArrayRef<QualType> Args); |
| 6617 | // Helper for ActOnFields to check for all function pointer members. |
| 6618 | bool EntirelyFunctionPointers(const RecordDecl *Record); |
| 6619 | |
| 6620 | // A cache representing if we've fully checked the various comparison category |
| 6621 | // types stored in ASTContext. The bit-index corresponds to the integer value |
| 6622 | // of a ComparisonCategoryType enumerator. |
| 6623 | llvm::SmallBitVector FullyCheckedComparisonCategories; |
| 6624 | |
| 6625 | /// Check if there is a field shadowing. |
| 6626 | void CheckShadowInheritedFields(const SourceLocation &Loc, |
| 6627 | DeclarationName FieldName, |
| 6628 | const CXXRecordDecl *RD, |
| 6629 | bool DeclIsField = true); |
| 6630 | |
| 6631 | ///@} |
| 6632 | |
| 6633 | // |
| 6634 | // |
| 6635 | // ------------------------------------------------------------------------- |
| 6636 | // |
| 6637 | // |
| 6638 | |
| 6639 | /// \name C++ Exception Specifications |
| 6640 | /// Implementations are in SemaExceptionSpec.cpp |
| 6641 | ///@{ |
| 6642 | |
| 6643 | public: |
| 6644 | /// All the overriding functions seen during a class definition |
| 6645 | /// that had their exception spec checks delayed, plus the overridden |
| 6646 | /// function. |
| 6647 | SmallVector<std::pair<const CXXMethodDecl *, const CXXMethodDecl *>, 2> |
| 6648 | DelayedOverridingExceptionSpecChecks; |
| 6649 | |
| 6650 | /// All the function redeclarations seen during a class definition that had |
| 6651 | /// their exception spec checks delayed, plus the prior declaration they |
| 6652 | /// should be checked against. Except during error recovery, the new decl |
| 6653 | /// should always be a friend declaration, as that's the only valid way to |
| 6654 | /// redeclare a special member before its class is complete. |
| 6655 | SmallVector<std::pair<FunctionDecl *, FunctionDecl *>, 2> |
| 6656 | DelayedEquivalentExceptionSpecChecks; |
| 6657 | |
| 6658 | /// Determine if we're in a case where we need to (incorrectly) eagerly |
| 6659 | /// parse an exception specification to work around a libstdc++ bug. |
| 6660 | bool isLibstdcxxEagerExceptionSpecHack(const Declarator &D); |
| 6661 | |
| 6662 | /// Check the given noexcept-specifier, convert its expression, and compute |
| 6663 | /// the appropriate ExceptionSpecificationType. |
| 6664 | ExprResult ActOnNoexceptSpec(Expr *NoexceptExpr, |
| 6665 | ExceptionSpecificationType &EST); |
| 6666 | |
| 6667 | CanThrowResult canThrow(const Stmt *E); |
| 6668 | /// Determine whether the callee of a particular function call can throw. |
| 6669 | /// E, D and Loc are all optional. |
| 6670 | static CanThrowResult canCalleeThrow(Sema &S, const Expr *E, const Decl *D, |
| 6671 | SourceLocation Loc = SourceLocation()); |
| 6672 | const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc, |
| 6673 | const FunctionProtoType *FPT); |
| 6674 | void UpdateExceptionSpec(FunctionDecl *FD, |
| 6675 | const FunctionProtoType::ExceptionSpecInfo &ESI); |
| 6676 | |
| 6677 | /// CheckSpecifiedExceptionType - Check if the given type is valid in an |
| 6678 | /// exception specification. Incomplete types, or pointers to incomplete types |
| 6679 | /// other than void are not allowed. |
| 6680 | /// |
| 6681 | /// \param[in,out] T The exception type. This will be decayed to a pointer |
| 6682 | /// type |
| 6683 | /// when the input is an array or a function type. |
| 6684 | bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range); |
| 6685 | |
| 6686 | /// CheckDistantExceptionSpec - Check if the given type is a pointer or |
| 6687 | /// pointer to member to a function with an exception specification. This |
| 6688 | /// means that it is invalid to add another level of indirection. |
| 6689 | bool CheckDistantExceptionSpec(QualType T); |
| 6690 | bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New); |
| 6691 | |
| 6692 | /// CheckEquivalentExceptionSpec - Check if the two types have equivalent |
| 6693 | /// exception specifications. Exception specifications are equivalent if |
| 6694 | /// they allow exactly the same set of exception types. It does not matter how |
| 6695 | /// that is achieved. See C++ [except.spec]p2. |
| 6696 | bool CheckEquivalentExceptionSpec(const FunctionProtoType *Old, |
| 6697 | SourceLocation OldLoc, |
| 6698 | const FunctionProtoType *New, |
| 6699 | SourceLocation NewLoc); |
| 6700 | bool CheckEquivalentExceptionSpec(const PartialDiagnostic &DiagID, |
| 6701 | const PartialDiagnostic &NoteID, |
| 6702 | const FunctionProtoType *Old, |
| 6703 | SourceLocation OldLoc, |
| 6704 | const FunctionProtoType *New, |
| 6705 | SourceLocation NewLoc); |
| 6706 | bool handlerCanCatch(QualType HandlerType, QualType ExceptionType); |
| 6707 | |
| 6708 | /// CheckExceptionSpecSubset - Check whether the second function type's |
| 6709 | /// exception specification is a subset (or equivalent) of the first function |
| 6710 | /// type. This is used by override and pointer assignment checks. |
| 6711 | bool CheckExceptionSpecSubset( |
| 6712 | const PartialDiagnostic &DiagID, const PartialDiagnostic &NestedDiagID, |
| 6713 | const PartialDiagnostic &NoteID, const PartialDiagnostic &NoThrowDiagID, |
| 6714 | const FunctionProtoType *Superset, bool SkipSupersetFirstParameter, |
| 6715 | SourceLocation SuperLoc, const FunctionProtoType *Subset, |
| 6716 | bool SkipSubsetFirstParameter, SourceLocation SubLoc); |
| 6717 | |
| 6718 | /// CheckParamExceptionSpec - Check if the parameter and return types of the |
| 6719 | /// two functions have equivalent exception specs. This is part of the |
| 6720 | /// assignment and override compatibility check. We do not check the |
| 6721 | /// parameters of parameter function pointers recursively, as no sane |
| 6722 | /// programmer would even be able to write such a function type. |
| 6723 | bool CheckParamExceptionSpec( |
| 6724 | const PartialDiagnostic &NestedDiagID, const PartialDiagnostic &NoteID, |
| 6725 | const FunctionProtoType *Target, bool SkipTargetFirstParameter, |
| 6726 | SourceLocation TargetLoc, const FunctionProtoType *Source, |
| 6727 | bool SkipSourceFirstParameter, SourceLocation SourceLoc); |
| 6728 | |
| 6729 | bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); |
| 6730 | |
| 6731 | /// CheckOverridingFunctionExceptionSpec - Checks whether the exception |
| 6732 | /// spec is a subset of base spec. |
| 6733 | bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, |
| 6734 | const CXXMethodDecl *Old); |
| 6735 | |
| 6736 | ///@} |
| 6737 | |
| 6738 | // |
| 6739 | // |
| 6740 | // ------------------------------------------------------------------------- |
| 6741 | // |
| 6742 | // |
| 6743 | |
| 6744 | /// \name Expressions |
| 6745 | /// Implementations are in SemaExpr.cpp |
| 6746 | ///@{ |
| 6747 | |
| 6748 | public: |
| 6749 | /// Describes how the expressions currently being parsed are |
| 6750 | /// evaluated at run-time, if at all. |
| 6751 | enum class ExpressionEvaluationContext { |
| 6752 | /// The current expression and its subexpressions occur within an |
| 6753 | /// unevaluated operand (C++11 [expr]p7), such as the subexpression of |
| 6754 | /// \c sizeof, where the type of the expression may be significant but |
| 6755 | /// no code will be generated to evaluate the value of the expression at |
| 6756 | /// run time. |
| 6757 | Unevaluated, |
| 6758 | |
| 6759 | /// The current expression occurs within a braced-init-list within |
| 6760 | /// an unevaluated operand. This is mostly like a regular unevaluated |
| 6761 | /// context, except that we still instantiate constexpr functions that are |
| 6762 | /// referenced here so that we can perform narrowing checks correctly. |
| 6763 | UnevaluatedList, |
| 6764 | |
| 6765 | /// The current expression occurs within a discarded statement. |
| 6766 | /// This behaves largely similarly to an unevaluated operand in preventing |
| 6767 | /// definitions from being required, but not in other ways. |
| 6768 | DiscardedStatement, |
| 6769 | |
| 6770 | /// The current expression occurs within an unevaluated |
| 6771 | /// operand that unconditionally permits abstract references to |
| 6772 | /// fields, such as a SIZE operator in MS-style inline assembly. |
| 6773 | UnevaluatedAbstract, |
| 6774 | |
| 6775 | /// The current context is "potentially evaluated" in C++11 terms, |
| 6776 | /// but the expression is evaluated at compile-time (like the values of |
| 6777 | /// cases in a switch statement). |
| 6778 | ConstantEvaluated, |
| 6779 | |
| 6780 | /// In addition of being constant evaluated, the current expression |
| 6781 | /// occurs in an immediate function context - either a consteval function |
| 6782 | /// or a consteval if statement. |
| 6783 | ImmediateFunctionContext, |
| 6784 | |
| 6785 | /// The current expression is potentially evaluated at run time, |
| 6786 | /// which means that code may be generated to evaluate the value of the |
| 6787 | /// expression at run time. |
| 6788 | PotentiallyEvaluated, |
| 6789 | |
| 6790 | /// The current expression is potentially evaluated, but any |
| 6791 | /// declarations referenced inside that expression are only used if |
| 6792 | /// in fact the current expression is used. |
| 6793 | /// |
| 6794 | /// This value is used when parsing default function arguments, for which |
| 6795 | /// we would like to provide diagnostics (e.g., passing non-POD arguments |
| 6796 | /// through varargs) but do not want to mark declarations as "referenced" |
| 6797 | /// until the default argument is used. |
| 6798 | PotentiallyEvaluatedIfUsed |
| 6799 | }; |
| 6800 | |
| 6801 | /// Store a set of either DeclRefExprs or MemberExprs that contain a reference |
| 6802 | /// to a variable (constant) that may or may not be odr-used in this Expr, and |
| 6803 | /// we won't know until all lvalue-to-rvalue and discarded value conversions |
| 6804 | /// have been applied to all subexpressions of the enclosing full expression. |
| 6805 | /// This is cleared at the end of each full expression. |
| 6806 | using MaybeODRUseExprSet = llvm::SmallSetVector<Expr *, 4>; |
| 6807 | MaybeODRUseExprSet MaybeODRUseExprs; |
| 6808 | |
| 6809 | using ImmediateInvocationCandidate = llvm::PointerIntPair<ConstantExpr *, 1>; |
| 6810 | |
| 6811 | /// Data structure used to record current or nested |
| 6812 | /// expression evaluation contexts. |
| 6813 | struct ExpressionEvaluationContextRecord { |
| 6814 | /// The expression evaluation context. |
| 6815 | ExpressionEvaluationContext Context; |
| 6816 | |
| 6817 | /// Whether the enclosing context needed a cleanup. |
| 6818 | CleanupInfo ParentCleanup; |
| 6819 | |
| 6820 | /// The number of active cleanup objects when we entered |
| 6821 | /// this expression evaluation context. |
| 6822 | unsigned NumCleanupObjects; |
| 6823 | |
| 6824 | MaybeODRUseExprSet SavedMaybeODRUseExprs; |
| 6825 | |
| 6826 | /// The lambdas that are present within this context, if it |
| 6827 | /// is indeed an unevaluated context. |
| 6828 | SmallVector<LambdaExpr *, 2> Lambdas; |
| 6829 | |
| 6830 | /// The declaration that provides context for lambda expressions |
| 6831 | /// and block literals if the normal declaration context does not |
| 6832 | /// suffice, e.g., in a default function argument. |
| 6833 | Decl *ManglingContextDecl; |
| 6834 | |
| 6835 | /// Declaration for initializer if one is currently being |
| 6836 | /// parsed. Used when an expression has a possibly unreachable |
| 6837 | /// diagnostic to reference the declaration as a whole. |
| 6838 | VarDecl *DeclForInitializer = nullptr; |
| 6839 | |
| 6840 | /// If we are processing a decltype type, a set of call expressions |
| 6841 | /// for which we have deferred checking the completeness of the return type. |
| 6842 | SmallVector<CallExpr *, 8> DelayedDecltypeCalls; |
| 6843 | |
| 6844 | /// If we are processing a decltype type, a set of temporary binding |
| 6845 | /// expressions for which we have deferred checking the destructor. |
| 6846 | SmallVector<CXXBindTemporaryExpr *, 8> DelayedDecltypeBinds; |
| 6847 | |
| 6848 | llvm::SmallPtrSet<const Expr *, 8> PossibleDerefs; |
| 6849 | |
| 6850 | /// Expressions appearing as the LHS of a volatile assignment in this |
| 6851 | /// context. We produce a warning for these when popping the context if |
| 6852 | /// they are not discarded-value expressions nor unevaluated operands. |
| 6853 | SmallVector<Expr *, 2> VolatileAssignmentLHSs; |
| 6854 | |
| 6855 | /// Set of candidates for starting an immediate invocation. |
| 6856 | llvm::SmallVector<ImmediateInvocationCandidate, 4> |
| 6857 | ImmediateInvocationCandidates; |
| 6858 | |
| 6859 | /// Set of DeclRefExprs referencing a consteval function when used in a |
| 6860 | /// context not already known to be immediately invoked. |
| 6861 | llvm::SmallPtrSet<DeclRefExpr *, 4> ReferenceToConsteval; |
| 6862 | |
| 6863 | /// P2718R0 - Lifetime extension in range-based for loops. |
| 6864 | /// MaterializeTemporaryExprs in for-range-init expressions which need to |
| 6865 | /// extend lifetime. Add MaterializeTemporaryExpr* if the value of |
| 6866 | /// InLifetimeExtendingContext is true. |
| 6867 | SmallVector<MaterializeTemporaryExpr *, 8> ForRangeLifetimeExtendTemps; |
| 6868 | |
| 6869 | /// Small set of gathered accesses to potentially misaligned members |
| 6870 | /// due to the packed attribute. |
| 6871 | SmallVector<MisalignedMember, 4> MisalignedMembers; |
| 6872 | |
| 6873 | /// \brief Describes whether we are in an expression constext which we have |
| 6874 | /// to handle differently. |
| 6875 | enum ExpressionKind { |
| 6876 | EK_Decltype, |
| 6877 | EK_TemplateArgument, |
| 6878 | EK_AttrArgument, |
| 6879 | EK_VariableInit, |
| 6880 | EK_Other |
| 6881 | } ExprContext; |
| 6882 | |
| 6883 | // A context can be nested in both a discarded statement context and |
| 6884 | // an immediate function context, so they need to be tracked independently. |
| 6885 | bool InDiscardedStatement; |
| 6886 | bool InImmediateFunctionContext; |
| 6887 | bool InImmediateEscalatingFunctionContext; |
| 6888 | |
| 6889 | bool IsCurrentlyCheckingDefaultArgumentOrInitializer = false; |
| 6890 | |
| 6891 | // We are in a constant context, but we also allow |
| 6892 | // non constant expressions, for example for array bounds (which may be |
| 6893 | // VLAs). |
| 6894 | bool InConditionallyConstantEvaluateContext = false; |
| 6895 | |
| 6896 | /// Whether we are currently in a context in which all temporaries must be |
| 6897 | /// lifetime-extended, even if they're not bound to a reference (for |
| 6898 | /// example, in a for-range initializer). |
| 6899 | bool InLifetimeExtendingContext = false; |
| 6900 | |
| 6901 | /// Whether evaluating an expression for a switch case label. |
| 6902 | bool IsCaseExpr = false; |
| 6903 | |
| 6904 | /// Whether we should rebuild CXXDefaultArgExpr and CXXDefaultInitExpr. |
| 6905 | bool RebuildDefaultArgOrDefaultInit = false; |
| 6906 | |
| 6907 | // When evaluating immediate functions in the initializer of a default |
| 6908 | // argument or default member initializer, this is the declaration whose |
| 6909 | // default initializer is being evaluated and the location of the call |
| 6910 | // or constructor definition. |
| 6911 | struct InitializationContext { |
| 6912 | InitializationContext(SourceLocation Loc, ValueDecl *Decl, |
| 6913 | DeclContext *Context) |
| 6914 | : Loc(Loc), Decl(Decl), Context(Context) { |
| 6915 | assert(Decl && Context && "invalid initialization context" ); |
| 6916 | } |
| 6917 | |
| 6918 | SourceLocation Loc; |
| 6919 | ValueDecl *Decl = nullptr; |
| 6920 | DeclContext *Context = nullptr; |
| 6921 | }; |
| 6922 | std::optional<InitializationContext> DelayedDefaultInitializationContext; |
| 6923 | |
| 6924 | ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context, |
| 6925 | unsigned NumCleanupObjects, |
| 6926 | CleanupInfo ParentCleanup, |
| 6927 | Decl *ManglingContextDecl, |
| 6928 | ExpressionKind ExprContext) |
| 6929 | : Context(Context), ParentCleanup(ParentCleanup), |
| 6930 | NumCleanupObjects(NumCleanupObjects), |
| 6931 | ManglingContextDecl(ManglingContextDecl), ExprContext(ExprContext), |
| 6932 | InDiscardedStatement(false), InImmediateFunctionContext(false), |
| 6933 | InImmediateEscalatingFunctionContext(false) {} |
| 6934 | |
| 6935 | bool isUnevaluated() const { |
| 6936 | return Context == ExpressionEvaluationContext::Unevaluated || |
| 6937 | Context == ExpressionEvaluationContext::UnevaluatedAbstract || |
| 6938 | Context == ExpressionEvaluationContext::UnevaluatedList; |
| 6939 | } |
| 6940 | |
| 6941 | bool isPotentiallyEvaluated() const { |
| 6942 | return Context == ExpressionEvaluationContext::PotentiallyEvaluated || |
| 6943 | Context == |
| 6944 | ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed || |
| 6945 | Context == ExpressionEvaluationContext::ConstantEvaluated; |
| 6946 | } |
| 6947 | |
| 6948 | bool isConstantEvaluated() const { |
| 6949 | return Context == ExpressionEvaluationContext::ConstantEvaluated || |
| 6950 | Context == ExpressionEvaluationContext::ImmediateFunctionContext; |
| 6951 | } |
| 6952 | |
| 6953 | bool isImmediateFunctionContext() const { |
| 6954 | return Context == ExpressionEvaluationContext::ImmediateFunctionContext || |
| 6955 | (Context == ExpressionEvaluationContext::DiscardedStatement && |
| 6956 | InImmediateFunctionContext) || |
| 6957 | // C++23 [expr.const]p14: |
| 6958 | // An expression or conversion is in an immediate function |
| 6959 | // context if it is potentially evaluated and either: |
| 6960 | // * its innermost enclosing non-block scope is a function |
| 6961 | // parameter scope of an immediate function, or |
| 6962 | // * its enclosing statement is enclosed by the compound- |
| 6963 | // statement of a consteval if statement. |
| 6964 | (Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
| 6965 | InImmediateFunctionContext); |
| 6966 | } |
| 6967 | |
| 6968 | bool isDiscardedStatementContext() const { |
| 6969 | return Context == ExpressionEvaluationContext::DiscardedStatement || |
| 6970 | ((Context == |
| 6971 | ExpressionEvaluationContext::ImmediateFunctionContext || |
| 6972 | isPotentiallyEvaluated()) && |
| 6973 | InDiscardedStatement); |
| 6974 | } |
| 6975 | }; |
| 6976 | |
| 6977 | const ExpressionEvaluationContextRecord ¤tEvaluationContext() const { |
| 6978 | assert(!ExprEvalContexts.empty() && |
| 6979 | "Must be in an expression evaluation context" ); |
| 6980 | return ExprEvalContexts.back(); |
| 6981 | } |
| 6982 | |
| 6983 | ExpressionEvaluationContextRecord ¤tEvaluationContext() { |
| 6984 | assert(!ExprEvalContexts.empty() && |
| 6985 | "Must be in an expression evaluation context" ); |
| 6986 | return ExprEvalContexts.back(); |
| 6987 | } |
| 6988 | |
| 6989 | ExpressionEvaluationContextRecord &parentEvaluationContext() { |
| 6990 | assert(ExprEvalContexts.size() >= 2 && |
| 6991 | "Must be in an expression evaluation context" ); |
| 6992 | return ExprEvalContexts[ExprEvalContexts.size() - 2]; |
| 6993 | } |
| 6994 | |
| 6995 | const ExpressionEvaluationContextRecord &parentEvaluationContext() const { |
| 6996 | return const_cast<Sema *>(this)->parentEvaluationContext(); |
| 6997 | } |
| 6998 | |
| 6999 | bool isAttrContext() const { |
| 7000 | return ExprEvalContexts.back().ExprContext == |
| 7001 | ExpressionEvaluationContextRecord::ExpressionKind::EK_AttrArgument; |
| 7002 | } |
| 7003 | |
| 7004 | /// Increment when we find a reference; decrement when we find an ignored |
| 7005 | /// assignment. Ultimately the value is 0 if every reference is an ignored |
| 7006 | /// assignment. |
| 7007 | llvm::DenseMap<const VarDecl *, int> RefsMinusAssignments; |
| 7008 | |
| 7009 | /// Used to control the generation of ExprWithCleanups. |
| 7010 | CleanupInfo Cleanup; |
| 7011 | |
| 7012 | /// ExprCleanupObjects - This is the stack of objects requiring |
| 7013 | /// cleanup that are created by the current full expression. |
| 7014 | SmallVector<ExprWithCleanups::CleanupObject, 8> ExprCleanupObjects; |
| 7015 | |
| 7016 | /// Determine whether the use of this declaration is valid, without |
| 7017 | /// emitting diagnostics. |
| 7018 | bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid); |
| 7019 | // A version of DiagnoseUseOfDecl that should be used if overload resolution |
| 7020 | // has been used to find this declaration, which means we don't have to bother |
| 7021 | // checking the trailing requires clause. |
| 7022 | bool DiagnoseUseOfOverloadedDecl(NamedDecl *D, SourceLocation Loc) { |
| 7023 | return DiagnoseUseOfDecl( |
| 7024 | D, Locs: Loc, /*UnknownObjCClass=*/UnknownObjCClass: nullptr, /*ObjCPropertyAccess=*/ObjCPropertyAccess: false, |
| 7025 | /*AvoidPartialAvailabilityChecks=*/AvoidPartialAvailabilityChecks: false, /*ClassReceiver=*/ClassReceiver: nullptr, |
| 7026 | /*SkipTrailingRequiresClause=*/SkipTrailingRequiresClause: true); |
| 7027 | } |
| 7028 | |
| 7029 | /// Determine whether the use of this declaration is valid, and |
| 7030 | /// emit any corresponding diagnostics. |
| 7031 | /// |
| 7032 | /// This routine diagnoses various problems with referencing |
| 7033 | /// declarations that can occur when using a declaration. For example, |
| 7034 | /// it might warn if a deprecated or unavailable declaration is being |
| 7035 | /// used, or produce an error (and return true) if a C++0x deleted |
| 7036 | /// function is being used. |
| 7037 | /// |
| 7038 | /// \returns true if there was an error (this declaration cannot be |
| 7039 | /// referenced), false otherwise. |
| 7040 | bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, |
| 7041 | const ObjCInterfaceDecl *UnknownObjCClass = nullptr, |
| 7042 | bool ObjCPropertyAccess = false, |
| 7043 | bool AvoidPartialAvailabilityChecks = false, |
| 7044 | ObjCInterfaceDecl *ClassReceiver = nullptr, |
| 7045 | bool SkipTrailingRequiresClause = false); |
| 7046 | |
| 7047 | /// Emit a note explaining that this function is deleted. |
| 7048 | void NoteDeletedFunction(FunctionDecl *FD); |
| 7049 | |
| 7050 | /// DiagnoseSentinelCalls - This routine checks whether a call or |
| 7051 | /// message-send is to a declaration with the sentinel attribute, and |
| 7052 | /// if so, it checks that the requirements of the sentinel are |
| 7053 | /// satisfied. |
| 7054 | void DiagnoseSentinelCalls(const NamedDecl *D, SourceLocation Loc, |
| 7055 | ArrayRef<Expr *> Args); |
| 7056 | |
| 7057 | void PushExpressionEvaluationContext( |
| 7058 | ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl = nullptr, |
| 7059 | ExpressionEvaluationContextRecord::ExpressionKind Type = |
| 7060 | ExpressionEvaluationContextRecord::EK_Other); |
| 7061 | |
| 7062 | void PushExpressionEvaluationContextForFunction( |
| 7063 | ExpressionEvaluationContext NewContext, FunctionDecl *FD); |
| 7064 | |
| 7065 | enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl }; |
| 7066 | void PushExpressionEvaluationContext( |
| 7067 | ExpressionEvaluationContext NewContext, ReuseLambdaContextDecl_t, |
| 7068 | ExpressionEvaluationContextRecord::ExpressionKind Type = |
| 7069 | ExpressionEvaluationContextRecord::EK_Other); |
| 7070 | void PopExpressionEvaluationContext(); |
| 7071 | |
| 7072 | void DiscardCleanupsInEvaluationContext(); |
| 7073 | |
| 7074 | ExprResult TransformToPotentiallyEvaluated(Expr *E); |
| 7075 | TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo); |
| 7076 | ExprResult HandleExprEvaluationContextForTypeof(Expr *E); |
| 7077 | |
| 7078 | /// Check whether E, which is either a discarded-value expression or an |
| 7079 | /// unevaluated operand, is a simple-assignment to a volatlie-qualified |
| 7080 | /// lvalue, and if so, remove it from the list of volatile-qualified |
| 7081 | /// assignments that we are going to warn are deprecated. |
| 7082 | void CheckUnusedVolatileAssignment(Expr *E); |
| 7083 | |
| 7084 | ExprResult ActOnConstantExpression(ExprResult Res); |
| 7085 | |
| 7086 | // Functions for marking a declaration referenced. These functions also |
| 7087 | // contain the relevant logic for marking if a reference to a function or |
| 7088 | // variable is an odr-use (in the C++11 sense). There are separate variants |
| 7089 | // for expressions referring to a decl; these exist because odr-use marking |
| 7090 | // needs to be delayed for some constant variables when we build one of the |
| 7091 | // named expressions. |
| 7092 | // |
| 7093 | // MightBeOdrUse indicates whether the use could possibly be an odr-use, and |
| 7094 | // should usually be true. This only needs to be set to false if the lack of |
| 7095 | // odr-use cannot be determined from the current context (for instance, |
| 7096 | // because the name denotes a virtual function and was written without an |
| 7097 | // explicit nested-name-specifier). |
| 7098 | void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse); |
| 7099 | |
| 7100 | /// Mark a function referenced, and check whether it is odr-used |
| 7101 | /// (C++ [basic.def.odr]p2, C99 6.9p3) |
| 7102 | void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, |
| 7103 | bool MightBeOdrUse = true); |
| 7104 | |
| 7105 | /// Mark a variable referenced, and check whether it is odr-used |
| 7106 | /// (C++ [basic.def.odr]p2, C99 6.9p3). Note that this should not be |
| 7107 | /// used directly for normal expressions referring to VarDecl. |
| 7108 | void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var); |
| 7109 | |
| 7110 | /// Perform reference-marking and odr-use handling for a DeclRefExpr. |
| 7111 | /// |
| 7112 | /// Note, this may change the dependence of the DeclRefExpr, and so needs to |
| 7113 | /// be handled with care if the DeclRefExpr is not newly-created. |
| 7114 | void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base = nullptr); |
| 7115 | |
| 7116 | /// Perform reference-marking and odr-use handling for a MemberExpr. |
| 7117 | void MarkMemberReferenced(MemberExpr *E); |
| 7118 | |
| 7119 | /// Perform reference-marking and odr-use handling for a FunctionParmPackExpr. |
| 7120 | void MarkFunctionParmPackReferenced(FunctionParmPackExpr *E); |
| 7121 | void MarkCaptureUsedInEnclosingContext(ValueDecl *Capture, SourceLocation Loc, |
| 7122 | unsigned CapturingScopeIndex); |
| 7123 | |
| 7124 | ExprResult CheckLValueToRValueConversionOperand(Expr *E); |
| 7125 | void CleanupVarDeclMarking(); |
| 7126 | |
| 7127 | /// Try to capture the given variable. |
| 7128 | /// |
| 7129 | /// \param Var The variable to capture. |
| 7130 | /// |
| 7131 | /// \param Loc The location at which the capture occurs. |
| 7132 | /// |
| 7133 | /// \param Kind The kind of capture, which may be implicit (for either a |
| 7134 | /// block or a lambda), or explicit by-value or by-reference (for a lambda). |
| 7135 | /// |
| 7136 | /// \param EllipsisLoc The location of the ellipsis, if one is provided in |
| 7137 | /// an explicit lambda capture. |
| 7138 | /// |
| 7139 | /// \param BuildAndDiagnose Whether we are actually supposed to add the |
| 7140 | /// captures or diagnose errors. If false, this routine merely check whether |
| 7141 | /// the capture can occur without performing the capture itself or complaining |
| 7142 | /// if the variable cannot be captured. |
| 7143 | /// |
| 7144 | /// \param CaptureType Will be set to the type of the field used to capture |
| 7145 | /// this variable in the innermost block or lambda. Only valid when the |
| 7146 | /// variable can be captured. |
| 7147 | /// |
| 7148 | /// \param DeclRefType Will be set to the type of a reference to the capture |
| 7149 | /// from within the current scope. Only valid when the variable can be |
| 7150 | /// captured. |
| 7151 | /// |
| 7152 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
| 7153 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
| 7154 | /// This is useful when enclosing lambdas must speculatively capture |
| 7155 | /// variables that may or may not be used in certain specializations of |
| 7156 | /// a nested generic lambda. |
| 7157 | /// |
| 7158 | /// \returns true if an error occurred (i.e., the variable cannot be |
| 7159 | /// captured) and false if the capture succeeded. |
| 7160 | bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc, |
| 7161 | TryCaptureKind Kind, SourceLocation EllipsisLoc, |
| 7162 | bool BuildAndDiagnose, QualType &CaptureType, |
| 7163 | QualType &DeclRefType, |
| 7164 | const unsigned *const FunctionScopeIndexToStopAt); |
| 7165 | |
| 7166 | /// Try to capture the given variable. |
| 7167 | bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc, |
| 7168 | TryCaptureKind Kind = TryCaptureKind::Implicit, |
| 7169 | SourceLocation EllipsisLoc = SourceLocation()); |
| 7170 | |
| 7171 | /// Checks if the variable must be captured. |
| 7172 | bool NeedToCaptureVariable(ValueDecl *Var, SourceLocation Loc); |
| 7173 | |
| 7174 | /// Given a variable, determine the type that a reference to that |
| 7175 | /// variable will have in the given scope. |
| 7176 | QualType getCapturedDeclRefType(ValueDecl *Var, SourceLocation Loc); |
| 7177 | |
| 7178 | /// Mark all of the declarations referenced within a particular AST node as |
| 7179 | /// referenced. Used when template instantiation instantiates a non-dependent |
| 7180 | /// type -- entities referenced by the type are now referenced. |
| 7181 | void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T); |
| 7182 | |
| 7183 | /// Mark any declarations that appear within this expression or any |
| 7184 | /// potentially-evaluated subexpressions as "referenced". |
| 7185 | /// |
| 7186 | /// \param SkipLocalVariables If true, don't mark local variables as |
| 7187 | /// 'referenced'. |
| 7188 | /// \param StopAt Subexpressions that we shouldn't recurse into. |
| 7189 | void MarkDeclarationsReferencedInExpr(Expr *E, |
| 7190 | bool SkipLocalVariables = false, |
| 7191 | ArrayRef<const Expr *> StopAt = {}); |
| 7192 | |
| 7193 | /// Try to convert an expression \p E to type \p Ty. Returns the result of the |
| 7194 | /// conversion. |
| 7195 | ExprResult tryConvertExprToType(Expr *E, QualType Ty); |
| 7196 | |
| 7197 | /// Conditionally issue a diagnostic based on the statements's reachability |
| 7198 | /// analysis. |
| 7199 | /// |
| 7200 | /// \param Stmts If Stmts is non-empty, delay reporting the diagnostic until |
| 7201 | /// the function body is parsed, and then do a basic reachability analysis to |
| 7202 | /// determine if the statement is reachable. If it is unreachable, the |
| 7203 | /// diagnostic will not be emitted. |
| 7204 | bool DiagIfReachable(SourceLocation Loc, ArrayRef<const Stmt *> Stmts, |
| 7205 | const PartialDiagnostic &PD); |
| 7206 | |
| 7207 | /// Conditionally issue a diagnostic based on the current |
| 7208 | /// evaluation context. |
| 7209 | /// |
| 7210 | /// \param Statement If Statement is non-null, delay reporting the |
| 7211 | /// diagnostic until the function body is parsed, and then do a basic |
| 7212 | /// reachability analysis to determine if the statement is reachable. |
| 7213 | /// If it is unreachable, the diagnostic will not be emitted. |
| 7214 | bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, |
| 7215 | const PartialDiagnostic &PD); |
| 7216 | /// Similar, but diagnostic is only produced if all the specified statements |
| 7217 | /// are reachable. |
| 7218 | bool DiagRuntimeBehavior(SourceLocation Loc, ArrayRef<const Stmt *> Stmts, |
| 7219 | const PartialDiagnostic &PD); |
| 7220 | |
| 7221 | // Primary Expressions. |
| 7222 | SourceRange getExprRange(Expr *E) const; |
| 7223 | |
| 7224 | ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, |
| 7225 | SourceLocation TemplateKWLoc, UnqualifiedId &Id, |
| 7226 | bool HasTrailingLParen, bool IsAddressOfOperand, |
| 7227 | CorrectionCandidateCallback *CCC = nullptr, |
| 7228 | bool IsInlineAsmIdentifier = false, |
| 7229 | Token *KeywordReplacement = nullptr); |
| 7230 | |
| 7231 | /// Decomposes the given name into a DeclarationNameInfo, its location, and |
| 7232 | /// possibly a list of template arguments. |
| 7233 | /// |
| 7234 | /// If this produces template arguments, it is permitted to call |
| 7235 | /// DecomposeTemplateName. |
| 7236 | /// |
| 7237 | /// This actually loses a lot of source location information for |
| 7238 | /// non-standard name kinds; we should consider preserving that in |
| 7239 | /// some way. |
| 7240 | void DecomposeUnqualifiedId(const UnqualifiedId &Id, |
| 7241 | TemplateArgumentListInfo &Buffer, |
| 7242 | DeclarationNameInfo &NameInfo, |
| 7243 | const TemplateArgumentListInfo *&TemplateArgs); |
| 7244 | |
| 7245 | /// Diagnose a lookup that found results in an enclosing class during error |
| 7246 | /// recovery. This usually indicates that the results were found in a |
| 7247 | /// dependent base class that could not be searched as part of a template |
| 7248 | /// definition. Always issues a diagnostic (though this may be only a warning |
| 7249 | /// in MS compatibility mode). |
| 7250 | /// |
| 7251 | /// Return \c true if the error is unrecoverable, or \c false if the caller |
| 7252 | /// should attempt to recover using these lookup results. |
| 7253 | bool DiagnoseDependentMemberLookup(const LookupResult &R); |
| 7254 | |
| 7255 | /// Diagnose an empty lookup. |
| 7256 | /// |
| 7257 | /// \return false if new lookup candidates were found |
| 7258 | bool |
| 7259 | DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, |
| 7260 | CorrectionCandidateCallback &CCC, |
| 7261 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
| 7262 | ArrayRef<Expr *> Args = {}, |
| 7263 | DeclContext *LookupCtx = nullptr); |
| 7264 | |
| 7265 | /// If \p D cannot be odr-used in the current expression evaluation context, |
| 7266 | /// return a reason explaining why. Otherwise, return NOUR_None. |
| 7267 | NonOdrUseReason getNonOdrUseReasonInCurrentContext(ValueDecl *D); |
| 7268 | |
| 7269 | DeclRefExpr *BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
| 7270 | SourceLocation Loc, |
| 7271 | const CXXScopeSpec *SS = nullptr); |
| 7272 | DeclRefExpr * |
| 7273 | BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
| 7274 | const DeclarationNameInfo &NameInfo, |
| 7275 | const CXXScopeSpec *SS = nullptr, |
| 7276 | NamedDecl *FoundD = nullptr, |
| 7277 | SourceLocation TemplateKWLoc = SourceLocation(), |
| 7278 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
| 7279 | |
| 7280 | /// BuildDeclRefExpr - Build an expression that references a |
| 7281 | /// declaration that does not require a closure capture. |
| 7282 | DeclRefExpr * |
| 7283 | BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
| 7284 | const DeclarationNameInfo &NameInfo, |
| 7285 | NestedNameSpecifierLoc NNS, NamedDecl *FoundD = nullptr, |
| 7286 | SourceLocation TemplateKWLoc = SourceLocation(), |
| 7287 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
| 7288 | |
| 7289 | bool UseArgumentDependentLookup(const CXXScopeSpec &SS, const LookupResult &R, |
| 7290 | bool HasTrailingLParen); |
| 7291 | |
| 7292 | /// BuildQualifiedDeclarationNameExpr - Build a C++ qualified |
| 7293 | /// declaration name, generally during template instantiation. |
| 7294 | /// There's a large number of things which don't need to be done along |
| 7295 | /// this path. |
| 7296 | ExprResult BuildQualifiedDeclarationNameExpr( |
| 7297 | CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, |
| 7298 | bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI = nullptr); |
| 7299 | |
| 7300 | ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, |
| 7301 | bool NeedsADL, |
| 7302 | bool AcceptInvalidDecl = false); |
| 7303 | |
| 7304 | /// Complete semantic analysis for a reference to the given declaration. |
| 7305 | ExprResult BuildDeclarationNameExpr( |
| 7306 | const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D, |
| 7307 | NamedDecl *FoundD = nullptr, |
| 7308 | const TemplateArgumentListInfo *TemplateArgs = nullptr, |
| 7309 | bool AcceptInvalidDecl = false); |
| 7310 | |
| 7311 | // ExpandFunctionLocalPredefinedMacros - Returns a new vector of Tokens, |
| 7312 | // where Tokens representing function local predefined macros (such as |
| 7313 | // __FUNCTION__) are replaced (expanded) with string-literal Tokens. |
| 7314 | std::vector<Token> ExpandFunctionLocalPredefinedMacros(ArrayRef<Token> Toks); |
| 7315 | |
| 7316 | ExprResult BuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK); |
| 7317 | ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind); |
| 7318 | ExprResult ActOnIntegerConstant(SourceLocation Loc, int64_t Val); |
| 7319 | |
| 7320 | bool CheckLoopHintExpr(Expr *E, SourceLocation Loc, bool AllowZero); |
| 7321 | |
| 7322 | ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr); |
| 7323 | ExprResult ActOnCharacterConstant(const Token &Tok, |
| 7324 | Scope *UDLScope = nullptr); |
| 7325 | ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E); |
| 7326 | ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, |
| 7327 | MultiExprArg Val); |
| 7328 | ExprResult ActOnCXXParenListInitExpr(ArrayRef<Expr *> Args, QualType T, |
| 7329 | unsigned NumUserSpecifiedExprs, |
| 7330 | SourceLocation InitLoc, |
| 7331 | SourceLocation LParenLoc, |
| 7332 | SourceLocation RParenLoc); |
| 7333 | |
| 7334 | /// ActOnStringLiteral - The specified tokens were lexed as pasted string |
| 7335 | /// fragments (e.g. "foo" "bar" L"baz"). The result string has to handle |
| 7336 | /// string concatenation ([C99 5.1.1.2, translation phase #6]), so it may come |
| 7337 | /// from multiple tokens. However, the common case is that StringToks points |
| 7338 | /// to one string. |
| 7339 | ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks, |
| 7340 | Scope *UDLScope = nullptr); |
| 7341 | |
| 7342 | ExprResult ActOnUnevaluatedStringLiteral(ArrayRef<Token> StringToks); |
| 7343 | |
| 7344 | /// ControllingExprOrType is either an opaque pointer coming out of a |
| 7345 | /// ParsedType or an Expr *. FIXME: it'd be better to split this interface |
| 7346 | /// into two so we don't take a void *, but that's awkward because one of |
| 7347 | /// the operands is either a ParsedType or an Expr *, which doesn't lend |
| 7348 | /// itself to generic code very well. |
| 7349 | ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, |
| 7350 | SourceLocation DefaultLoc, |
| 7351 | SourceLocation RParenLoc, |
| 7352 | bool PredicateIsExpr, |
| 7353 | void *ControllingExprOrType, |
| 7354 | ArrayRef<ParsedType> ArgTypes, |
| 7355 | ArrayRef<Expr *> ArgExprs); |
| 7356 | /// ControllingExprOrType is either a TypeSourceInfo * or an Expr *. FIXME: |
| 7357 | /// it'd be better to split this interface into two so we don't take a |
| 7358 | /// void *, but see the FIXME on ActOnGenericSelectionExpr as to why that |
| 7359 | /// isn't a trivial change. |
| 7360 | ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, |
| 7361 | SourceLocation DefaultLoc, |
| 7362 | SourceLocation RParenLoc, |
| 7363 | bool PredicateIsExpr, |
| 7364 | void *ControllingExprOrType, |
| 7365 | ArrayRef<TypeSourceInfo *> Types, |
| 7366 | ArrayRef<Expr *> Exprs); |
| 7367 | |
| 7368 | // Binary/Unary Operators. 'Tok' is the token for the operator. |
| 7369 | ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, |
| 7370 | Expr *InputExpr, bool IsAfterAmp = false); |
| 7371 | ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc, |
| 7372 | Expr *Input, bool IsAfterAmp = false); |
| 7373 | |
| 7374 | /// Unary Operators. 'Tok' is the token for the operator. |
| 7375 | ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, tok::TokenKind Op, |
| 7376 | Expr *Input, bool IsAfterAmp = false); |
| 7377 | |
| 7378 | /// Determine whether the given expression is a qualified member |
| 7379 | /// access expression, of a form that could be turned into a pointer to member |
| 7380 | /// with the address-of operator. |
| 7381 | bool isQualifiedMemberAccess(Expr *E); |
| 7382 | bool CheckUseOfCXXMethodAsAddressOfOperand(SourceLocation OpLoc, |
| 7383 | const Expr *Op, |
| 7384 | const CXXMethodDecl *MD); |
| 7385 | |
| 7386 | /// CheckAddressOfOperand - The operand of & must be either a function |
| 7387 | /// designator or an lvalue designating an object. If it is an lvalue, the |
| 7388 | /// object cannot be declared with storage class register or be a bit field. |
| 7389 | /// Note: The usual conversions are *not* applied to the operand of the & |
| 7390 | /// operator (C99 6.3.2.1p[2-4]), and its result is never an lvalue. |
| 7391 | /// In C++, the operand might be an overloaded function name, in which case |
| 7392 | /// we allow the '&' but retain the overloaded-function type. |
| 7393 | QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc); |
| 7394 | |
| 7395 | /// ActOnAlignasTypeArgument - Handle @c alignas(type-id) and @c |
| 7396 | /// _Alignas(type-name) . |
| 7397 | /// [dcl.align] An alignment-specifier of the form |
| 7398 | /// alignas(type-id) has the same effect as alignas(alignof(type-id)). |
| 7399 | /// |
| 7400 | /// [N1570 6.7.5] _Alignas(type-name) is equivalent to |
| 7401 | /// _Alignas(_Alignof(type-name)). |
| 7402 | bool ActOnAlignasTypeArgument(StringRef KWName, ParsedType Ty, |
| 7403 | SourceLocation OpLoc, SourceRange R); |
| 7404 | bool CheckAlignasTypeArgument(StringRef KWName, TypeSourceInfo *TInfo, |
| 7405 | SourceLocation OpLoc, SourceRange R); |
| 7406 | |
| 7407 | /// Build a sizeof or alignof expression given a type operand. |
| 7408 | ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, |
| 7409 | SourceLocation OpLoc, |
| 7410 | UnaryExprOrTypeTrait ExprKind, |
| 7411 | SourceRange R); |
| 7412 | |
| 7413 | /// Build a sizeof or alignof expression given an expression |
| 7414 | /// operand. |
| 7415 | ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, |
| 7416 | UnaryExprOrTypeTrait ExprKind); |
| 7417 | |
| 7418 | /// ActOnUnaryExprOrTypeTraitExpr - Handle @c sizeof(type) and @c sizeof @c |
| 7419 | /// expr and the same for @c alignof and @c __alignof |
| 7420 | /// Note that the ArgRange is invalid if isType is false. |
| 7421 | ExprResult ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, |
| 7422 | UnaryExprOrTypeTrait ExprKind, |
| 7423 | bool IsType, void *TyOrEx, |
| 7424 | SourceRange ArgRange); |
| 7425 | |
| 7426 | /// Check for operands with placeholder types and complain if found. |
| 7427 | /// Returns ExprError() if there was an error and no recovery was possible. |
| 7428 | ExprResult CheckPlaceholderExpr(Expr *E); |
| 7429 | bool CheckVecStepExpr(Expr *E); |
| 7430 | |
| 7431 | /// Check the constraints on expression operands to unary type expression |
| 7432 | /// and type traits. |
| 7433 | /// |
| 7434 | /// Completes any types necessary and validates the constraints on the operand |
| 7435 | /// expression. The logic mostly mirrors the type-based overload, but may |
| 7436 | /// modify the expression as it completes the type for that expression through |
| 7437 | /// template instantiation, etc. |
| 7438 | bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind); |
| 7439 | |
| 7440 | /// Check the constraints on operands to unary expression and type |
| 7441 | /// traits. |
| 7442 | /// |
| 7443 | /// This will complete any types necessary, and validate the various |
| 7444 | /// constraints on those operands. |
| 7445 | /// |
| 7446 | /// The UsualUnaryConversions() function is *not* called by this routine. |
| 7447 | /// C99 6.3.2.1p[2-4] all state: |
| 7448 | /// Except when it is the operand of the sizeof operator ... |
| 7449 | /// |
| 7450 | /// C++ [expr.sizeof]p4 |
| 7451 | /// The lvalue-to-rvalue, array-to-pointer, and function-to-pointer |
| 7452 | /// standard conversions are not applied to the operand of sizeof. |
| 7453 | /// |
| 7454 | /// This policy is followed for all of the unary trait expressions. |
| 7455 | bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc, |
| 7456 | SourceRange ExprRange, |
| 7457 | UnaryExprOrTypeTrait ExprKind, |
| 7458 | StringRef KWName); |
| 7459 | |
| 7460 | ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, |
| 7461 | tok::TokenKind Kind, Expr *Input); |
| 7462 | |
| 7463 | ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, |
| 7464 | MultiExprArg ArgExprs, |
| 7465 | SourceLocation RLoc); |
| 7466 | ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, |
| 7467 | Expr *Idx, SourceLocation RLoc); |
| 7468 | |
| 7469 | ExprResult CreateBuiltinMatrixSingleSubscriptExpr(Expr *Base, Expr *RowIdx, |
| 7470 | SourceLocation RBLoc); |
| 7471 | |
| 7472 | ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, |
| 7473 | Expr *ColumnIdx, |
| 7474 | SourceLocation RBLoc); |
| 7475 | |
| 7476 | /// ConvertArgumentsForCall - Converts the arguments specified in |
| 7477 | /// Args/NumArgs to the parameter types of the function FDecl with |
| 7478 | /// function prototype Proto. Call is the call expression itself, and |
| 7479 | /// Fn is the function expression. For a C++ member function, this |
| 7480 | /// routine does not attempt to convert the object argument. Returns |
| 7481 | /// true if the call is ill-formed. |
| 7482 | bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, FunctionDecl *FDecl, |
| 7483 | const FunctionProtoType *Proto, |
| 7484 | ArrayRef<Expr *> Args, SourceLocation RParenLoc, |
| 7485 | bool ExecConfig = false); |
| 7486 | |
| 7487 | /// CheckStaticArrayArgument - If the given argument corresponds to a static |
| 7488 | /// array parameter, check that it is non-null, and that if it is formed by |
| 7489 | /// array-to-pointer decay, the underlying array is sufficiently large. |
| 7490 | /// |
| 7491 | /// C99 6.7.5.3p7: If the keyword static also appears within the [ and ] of |
| 7492 | /// the array type derivation, then for each call to the function, the value |
| 7493 | /// of the corresponding actual argument shall provide access to the first |
| 7494 | /// element of an array with at least as many elements as specified by the |
| 7495 | /// size expression. |
| 7496 | void CheckStaticArrayArgument(SourceLocation CallLoc, ParmVarDecl *Param, |
| 7497 | const Expr *ArgExpr); |
| 7498 | |
| 7499 | /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. |
| 7500 | /// This provides the location of the left/right parens and a list of comma |
| 7501 | /// locations. |
| 7502 | ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, |
| 7503 | MultiExprArg ArgExprs, SourceLocation RParenLoc, |
| 7504 | Expr *ExecConfig = nullptr); |
| 7505 | |
| 7506 | /// BuildCallExpr - Handle a call to Fn with the specified array of arguments. |
| 7507 | /// This provides the location of the left/right parens and a list of comma |
| 7508 | /// locations. |
| 7509 | ExprResult BuildCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, |
| 7510 | MultiExprArg ArgExprs, SourceLocation RParenLoc, |
| 7511 | Expr *ExecConfig = nullptr, |
| 7512 | bool IsExecConfig = false, |
| 7513 | bool AllowRecovery = false); |
| 7514 | |
| 7515 | /// BuildBuiltinCallExpr - Create a call to a builtin function specified by Id |
| 7516 | // with the specified CallArgs |
| 7517 | Expr *BuildBuiltinCallExpr(SourceLocation Loc, Builtin::ID Id, |
| 7518 | MultiExprArg CallArgs); |
| 7519 | |
| 7520 | using ADLCallKind = CallExpr::ADLCallKind; |
| 7521 | |
| 7522 | /// BuildResolvedCallExpr - Build a call to a resolved expression, |
| 7523 | /// i.e. an expression not of \p OverloadTy. The expression should |
| 7524 | /// unary-convert to an expression of function-pointer or |
| 7525 | /// block-pointer type. |
| 7526 | /// |
| 7527 | /// \param NDecl the declaration being called, if available |
| 7528 | ExprResult |
| 7529 | BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, SourceLocation LParenLoc, |
| 7530 | ArrayRef<Expr *> Arg, SourceLocation RParenLoc, |
| 7531 | Expr *Config = nullptr, bool IsExecConfig = false, |
| 7532 | ADLCallKind UsesADL = ADLCallKind::NotADL); |
| 7533 | |
| 7534 | ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, Declarator &D, |
| 7535 | ParsedType &Ty, SourceLocation RParenLoc, |
| 7536 | Expr *CastExpr); |
| 7537 | |
| 7538 | /// Prepares for a scalar cast, performing all the necessary stages |
| 7539 | /// except the final cast and returning the kind required. |
| 7540 | CastKind PrepareScalarCast(ExprResult &src, QualType destType); |
| 7541 | |
| 7542 | /// Build an altivec or OpenCL literal. |
| 7543 | ExprResult BuildVectorLiteral(SourceLocation LParenLoc, |
| 7544 | SourceLocation RParenLoc, Expr *E, |
| 7545 | TypeSourceInfo *TInfo); |
| 7546 | |
| 7547 | /// This is not an AltiVec-style cast or or C++ direct-initialization, so turn |
| 7548 | /// the ParenListExpr into a sequence of comma binary operators. |
| 7549 | ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); |
| 7550 | |
| 7551 | ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, ParsedType Ty, |
| 7552 | SourceLocation RParenLoc, Expr *InitExpr); |
| 7553 | |
| 7554 | ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, |
| 7555 | TypeSourceInfo *TInfo, |
| 7556 | SourceLocation RParenLoc, |
| 7557 | Expr *LiteralExpr); |
| 7558 | |
| 7559 | ExprResult ActOnInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList, |
| 7560 | SourceLocation RBraceLoc); |
| 7561 | |
| 7562 | ExprResult BuildInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList, |
| 7563 | SourceLocation RBraceLoc); |
| 7564 | |
| 7565 | /// Binary Operators. 'Tok' is the token for the operator. |
| 7566 | ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, tok::TokenKind Kind, |
| 7567 | Expr *LHSExpr, Expr *RHSExpr); |
| 7568 | ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, |
| 7569 | Expr *LHSExpr, Expr *RHSExpr, |
| 7570 | bool ForFoldExpression = false); |
| 7571 | |
| 7572 | /// CreateBuiltinBinOp - Creates a new built-in binary operation with |
| 7573 | /// operator @p Opc at location @c TokLoc. This routine only supports |
| 7574 | /// built-in operations; ActOnBinOp handles overloaded operators. |
| 7575 | ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, |
| 7576 | Expr *LHSExpr, Expr *RHSExpr, |
| 7577 | bool ForFoldExpression = false); |
| 7578 | void LookupBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, |
| 7579 | UnresolvedSetImpl &Functions); |
| 7580 | |
| 7581 | /// Look for instances where it is likely the comma operator is confused with |
| 7582 | /// another operator. There is an explicit list of acceptable expressions for |
| 7583 | /// the left hand side of the comma operator, otherwise emit a warning. |
| 7584 | void DiagnoseCommaOperator(const Expr *LHS, SourceLocation Loc); |
| 7585 | |
| 7586 | /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
| 7587 | /// in the case of a the GNU conditional expr extension. |
| 7588 | ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, |
| 7589 | SourceLocation ColonLoc, Expr *CondExpr, |
| 7590 | Expr *LHSExpr, Expr *RHSExpr); |
| 7591 | |
| 7592 | /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". |
| 7593 | ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, |
| 7594 | LabelDecl *TheDecl); |
| 7595 | |
| 7596 | void ActOnStartStmtExpr(); |
| 7597 | ExprResult ActOnStmtExpr(Scope *S, SourceLocation LPLoc, Stmt *SubStmt, |
| 7598 | SourceLocation RPLoc); |
| 7599 | ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, |
| 7600 | SourceLocation RPLoc, unsigned TemplateDepth); |
| 7601 | // Handle the final expression in a statement expression. |
| 7602 | ExprResult ActOnStmtExprResult(ExprResult E); |
| 7603 | void ActOnStmtExprError(); |
| 7604 | |
| 7605 | // __builtin_offsetof(type, identifier(.identifier|[expr])*) |
| 7606 | struct OffsetOfComponent { |
| 7607 | SourceLocation LocStart, LocEnd; |
| 7608 | bool isBrackets; // true if [expr], false if .ident |
| 7609 | union { |
| 7610 | IdentifierInfo *IdentInfo; |
| 7611 | Expr *E; |
| 7612 | } U; |
| 7613 | }; |
| 7614 | |
| 7615 | /// __builtin_offsetof(type, a.b[123][456].c) |
| 7616 | ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, |
| 7617 | TypeSourceInfo *TInfo, |
| 7618 | ArrayRef<OffsetOfComponent> Components, |
| 7619 | SourceLocation RParenLoc); |
| 7620 | ExprResult ActOnBuiltinOffsetOf(Scope *S, SourceLocation BuiltinLoc, |
| 7621 | SourceLocation TypeLoc, |
| 7622 | ParsedType ParsedArgTy, |
| 7623 | ArrayRef<OffsetOfComponent> Components, |
| 7624 | SourceLocation RParenLoc); |
| 7625 | |
| 7626 | // __builtin_choose_expr(constExpr, expr1, expr2) |
| 7627 | ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, Expr *CondExpr, |
| 7628 | Expr *LHSExpr, Expr *RHSExpr, |
| 7629 | SourceLocation RPLoc); |
| 7630 | |
| 7631 | // __builtin_va_arg(expr, type) |
| 7632 | ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty, |
| 7633 | SourceLocation RPLoc); |
| 7634 | ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, |
| 7635 | TypeSourceInfo *TInfo, SourceLocation RPLoc); |
| 7636 | |
| 7637 | // __builtin_LINE(), __builtin_FUNCTION(), __builtin_FUNCSIG(), |
| 7638 | // __builtin_FILE(), __builtin_COLUMN(), __builtin_source_location() |
| 7639 | ExprResult ActOnSourceLocExpr(SourceLocIdentKind Kind, |
| 7640 | SourceLocation BuiltinLoc, |
| 7641 | SourceLocation RPLoc); |
| 7642 | |
| 7643 | // #embed |
| 7644 | ExprResult ActOnEmbedExpr(SourceLocation EmbedKeywordLoc, |
| 7645 | StringLiteral *BinaryData, StringRef FileName); |
| 7646 | |
| 7647 | // Build a potentially resolved SourceLocExpr. |
| 7648 | ExprResult BuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy, |
| 7649 | SourceLocation BuiltinLoc, SourceLocation RPLoc, |
| 7650 | DeclContext *ParentContext); |
| 7651 | |
| 7652 | // __null |
| 7653 | ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); |
| 7654 | |
| 7655 | bool CheckCaseExpression(Expr *E); |
| 7656 | |
| 7657 | //===------------------------- "Block" Extension ------------------------===// |
| 7658 | |
| 7659 | /// ActOnBlockStart - This callback is invoked when a block literal is |
| 7660 | /// started. |
| 7661 | void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); |
| 7662 | |
| 7663 | /// ActOnBlockArguments - This callback allows processing of block arguments. |
| 7664 | /// If there are no arguments, this is still invoked. |
| 7665 | void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, |
| 7666 | Scope *CurScope); |
| 7667 | |
| 7668 | /// ActOnBlockError - If there is an error parsing a block, this callback |
| 7669 | /// is invoked to pop the information about the block from the action impl. |
| 7670 | void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); |
| 7671 | |
| 7672 | /// ActOnBlockStmtExpr - This is called when the body of a block statement |
| 7673 | /// literal was successfully completed. ^(int x){...} |
| 7674 | ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, |
| 7675 | Scope *CurScope); |
| 7676 | |
| 7677 | //===---------------------------- Clang Extensions ----------------------===// |
| 7678 | |
| 7679 | /// ActOnConvertVectorExpr - create a new convert-vector expression from the |
| 7680 | /// provided arguments. |
| 7681 | /// |
| 7682 | /// __builtin_convertvector( value, dst type ) |
| 7683 | /// |
| 7684 | ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy, |
| 7685 | SourceLocation BuiltinLoc, |
| 7686 | SourceLocation RParenLoc); |
| 7687 | |
| 7688 | //===---------------------------- OpenCL Features -----------------------===// |
| 7689 | |
| 7690 | /// Parse a __builtin_astype expression. |
| 7691 | /// |
| 7692 | /// __builtin_astype( value, dst type ) |
| 7693 | /// |
| 7694 | ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy, |
| 7695 | SourceLocation BuiltinLoc, |
| 7696 | SourceLocation RParenLoc); |
| 7697 | |
| 7698 | /// Create a new AsTypeExpr node (bitcast) from the arguments. |
| 7699 | ExprResult BuildAsTypeExpr(Expr *E, QualType DestTy, |
| 7700 | SourceLocation BuiltinLoc, |
| 7701 | SourceLocation RParenLoc); |
| 7702 | |
| 7703 | /// Attempts to produce a RecoveryExpr after some AST node cannot be created. |
| 7704 | ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, |
| 7705 | ArrayRef<Expr *> SubExprs, |
| 7706 | QualType T = QualType()); |
| 7707 | |
| 7708 | /// Cast a base object to a member's actual type. |
| 7709 | /// |
| 7710 | /// There are two relevant checks: |
| 7711 | /// |
| 7712 | /// C++ [class.access.base]p7: |
| 7713 | /// |
| 7714 | /// If a class member access operator [...] is used to access a non-static |
| 7715 | /// data member or non-static member function, the reference is ill-formed |
| 7716 | /// if the left operand [...] cannot be implicitly converted to a pointer to |
| 7717 | /// the naming class of the right operand. |
| 7718 | /// |
| 7719 | /// C++ [expr.ref]p7: |
| 7720 | /// |
| 7721 | /// If E2 is a non-static data member or a non-static member function, the |
| 7722 | /// program is ill-formed if the class of which E2 is directly a member is |
| 7723 | /// an ambiguous base (11.8) of the naming class (11.9.3) of E2. |
| 7724 | /// |
| 7725 | /// Note that the latter check does not consider access; the access of the |
| 7726 | /// "real" base class is checked as appropriate when checking the access of |
| 7727 | /// the member name. |
| 7728 | ExprResult PerformObjectMemberConversion(Expr *From, |
| 7729 | NestedNameSpecifier Qualifier, |
| 7730 | NamedDecl *FoundDecl, |
| 7731 | NamedDecl *Member); |
| 7732 | |
| 7733 | /// CheckCallReturnType - Checks that a call expression's return type is |
| 7734 | /// complete. Returns true on failure. The location passed in is the location |
| 7735 | /// that best represents the call. |
| 7736 | bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc, |
| 7737 | CallExpr *CE, FunctionDecl *FD); |
| 7738 | |
| 7739 | /// Emit a warning for all pending noderef expressions that we recorded. |
| 7740 | void WarnOnPendingNoDerefs(ExpressionEvaluationContextRecord &Rec); |
| 7741 | |
| 7742 | ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field); |
| 7743 | |
| 7744 | /// Instantiate or parse a C++ default argument expression as necessary. |
| 7745 | /// Return true on error. |
| 7746 | bool CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, |
| 7747 | ParmVarDecl *Param, Expr *Init = nullptr, |
| 7748 | bool SkipImmediateInvocations = true); |
| 7749 | |
| 7750 | /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating |
| 7751 | /// the default expr if needed. |
| 7752 | ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, |
| 7753 | ParmVarDecl *Param, Expr *Init = nullptr); |
| 7754 | |
| 7755 | /// Wrap the expression in a ConstantExpr if it is a potential immediate |
| 7756 | /// invocation. |
| 7757 | ExprResult CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl); |
| 7758 | |
| 7759 | void MarkExpressionAsImmediateEscalating(Expr *E); |
| 7760 | |
| 7761 | // Check that the SME attributes for PSTATE.ZA and PSTATE.SM are compatible. |
| 7762 | bool IsInvalidSMECallConversion(QualType FromType, QualType ToType); |
| 7763 | |
| 7764 | /// Abstract base class used for diagnosing integer constant |
| 7765 | /// expression violations. |
| 7766 | class VerifyICEDiagnoser { |
| 7767 | public: |
| 7768 | bool Suppress; |
| 7769 | |
| 7770 | VerifyICEDiagnoser(bool Suppress = false) : Suppress(Suppress) {} |
| 7771 | |
| 7772 | virtual SemaDiagnosticBuilder |
| 7773 | diagnoseNotICEType(Sema &S, SourceLocation Loc, QualType T); |
| 7774 | virtual SemaDiagnosticBuilder diagnoseNotICE(Sema &S, |
| 7775 | SourceLocation Loc) = 0; |
| 7776 | virtual SemaDiagnosticBuilder diagnoseFold(Sema &S, SourceLocation Loc); |
| 7777 | virtual ~VerifyICEDiagnoser() {} |
| 7778 | }; |
| 7779 | |
| 7780 | /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE, |
| 7781 | /// and reports the appropriate diagnostics. Returns false on success. |
| 7782 | /// Can optionally return the value of the expression. |
| 7783 | ExprResult |
| 7784 | VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, |
| 7785 | VerifyICEDiagnoser &Diagnoser, |
| 7786 | AllowFoldKind CanFold = AllowFoldKind::No); |
| 7787 | ExprResult |
| 7788 | VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, |
| 7789 | unsigned DiagID, |
| 7790 | AllowFoldKind CanFold = AllowFoldKind::No); |
| 7791 | ExprResult |
| 7792 | VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result = nullptr, |
| 7793 | AllowFoldKind CanFold = AllowFoldKind::No); |
| 7794 | ExprResult |
| 7795 | VerifyIntegerConstantExpression(Expr *E, |
| 7796 | AllowFoldKind CanFold = AllowFoldKind::No) { |
| 7797 | return VerifyIntegerConstantExpression(E, Result: nullptr, CanFold); |
| 7798 | } |
| 7799 | |
| 7800 | /// DiagnoseAssignmentAsCondition - Given that an expression is |
| 7801 | /// being used as a boolean condition, warn if it's an assignment. |
| 7802 | void DiagnoseAssignmentAsCondition(Expr *E); |
| 7803 | |
| 7804 | /// Redundant parentheses over an equality comparison can indicate |
| 7805 | /// that the user intended an assignment used as condition. |
| 7806 | void (ParenExpr *ParenE); |
| 7807 | |
| 7808 | class FullExprArg { |
| 7809 | public: |
| 7810 | FullExprArg() : E(nullptr) {} |
| 7811 | FullExprArg(Sema &actions) : E(nullptr) {} |
| 7812 | |
| 7813 | ExprResult release() { return E; } |
| 7814 | |
| 7815 | Expr *get() const { return E; } |
| 7816 | |
| 7817 | Expr *operator->() { return E; } |
| 7818 | |
| 7819 | private: |
| 7820 | // FIXME: No need to make the entire Sema class a friend when it's just |
| 7821 | // Sema::MakeFullExpr that needs access to the constructor below. |
| 7822 | friend class Sema; |
| 7823 | |
| 7824 | explicit FullExprArg(Expr *expr) : E(expr) {} |
| 7825 | |
| 7826 | Expr *E; |
| 7827 | }; |
| 7828 | |
| 7829 | FullExprArg MakeFullExpr(Expr *Arg) { |
| 7830 | return MakeFullExpr(Arg, CC: Arg ? Arg->getExprLoc() : SourceLocation()); |
| 7831 | } |
| 7832 | FullExprArg MakeFullExpr(Expr *Arg, SourceLocation CC) { |
| 7833 | return FullExprArg( |
| 7834 | ActOnFinishFullExpr(Expr: Arg, CC, /*DiscardedValue*/ DiscardedValue: false).get()); |
| 7835 | } |
| 7836 | FullExprArg MakeFullDiscardedValueExpr(Expr *Arg) { |
| 7837 | ExprResult FE = |
| 7838 | ActOnFinishFullExpr(Expr: Arg, CC: Arg ? Arg->getExprLoc() : SourceLocation(), |
| 7839 | /*DiscardedValue*/ DiscardedValue: true); |
| 7840 | return FullExprArg(FE.get()); |
| 7841 | } |
| 7842 | |
| 7843 | class ConditionResult { |
| 7844 | Decl *ConditionVar; |
| 7845 | ExprResult Condition; |
| 7846 | bool Invalid; |
| 7847 | std::optional<bool> KnownValue; |
| 7848 | |
| 7849 | friend class Sema; |
| 7850 | ConditionResult(Sema &S, Decl *ConditionVar, ExprResult Condition, |
| 7851 | bool IsConstexpr) |
| 7852 | : ConditionVar(ConditionVar), Condition(Condition), Invalid(false) { |
| 7853 | if (IsConstexpr && Condition.get()) { |
| 7854 | if (std::optional<llvm::APSInt> Val = |
| 7855 | Condition.get()->getIntegerConstantExpr(Ctx: S.Context)) { |
| 7856 | KnownValue = !!(*Val); |
| 7857 | } |
| 7858 | } |
| 7859 | } |
| 7860 | explicit ConditionResult(bool Invalid) |
| 7861 | : ConditionVar(nullptr), Condition(Invalid), Invalid(Invalid), |
| 7862 | KnownValue(std::nullopt) {} |
| 7863 | |
| 7864 | public: |
| 7865 | ConditionResult() : ConditionResult(false) {} |
| 7866 | bool isInvalid() const { return Invalid; } |
| 7867 | std::pair<VarDecl *, Expr *> get() const { |
| 7868 | return std::make_pair(x: cast_or_null<VarDecl>(Val: ConditionVar), |
| 7869 | y: Condition.get()); |
| 7870 | } |
| 7871 | std::optional<bool> getKnownValue() const { return KnownValue; } |
| 7872 | }; |
| 7873 | static ConditionResult ConditionError() { return ConditionResult(true); } |
| 7874 | |
| 7875 | /// CheckBooleanCondition - Diagnose problems involving the use of |
| 7876 | /// the given expression as a boolean condition (e.g. in an if |
| 7877 | /// statement). Also performs the standard function and array |
| 7878 | /// decays, possibly changing the input variable. |
| 7879 | /// |
| 7880 | /// \param Loc - A location associated with the condition, e.g. the |
| 7881 | /// 'if' keyword. |
| 7882 | /// \return true iff there were any errors |
| 7883 | ExprResult CheckBooleanCondition(SourceLocation Loc, Expr *E, |
| 7884 | bool IsConstexpr = false); |
| 7885 | |
| 7886 | enum class ConditionKind { |
| 7887 | Boolean, ///< A boolean condition, from 'if', 'while', 'for', or 'do'. |
| 7888 | ConstexprIf, ///< A constant boolean condition from 'if constexpr'. |
| 7889 | Switch ///< An integral condition for a 'switch' statement. |
| 7890 | }; |
| 7891 | |
| 7892 | ConditionResult ActOnCondition(Scope *S, SourceLocation Loc, Expr *SubExpr, |
| 7893 | ConditionKind CK, bool MissingOK = false); |
| 7894 | |
| 7895 | QualType CheckConditionalOperands( // C99 6.5.15 |
| 7896 | ExprResult &Cond, ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, |
| 7897 | ExprObjectKind &OK, SourceLocation QuestionLoc); |
| 7898 | |
| 7899 | /// Emit a specialized diagnostic when one expression is a null pointer |
| 7900 | /// constant and the other is not a pointer. Returns true if a diagnostic is |
| 7901 | /// emitted. |
| 7902 | bool DiagnoseConditionalForNull(const Expr *LHSExpr, const Expr *RHSExpr, |
| 7903 | SourceLocation QuestionLoc); |
| 7904 | |
| 7905 | /// type checking for vector binary operators. |
| 7906 | QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS, |
| 7907 | SourceLocation Loc, bool IsCompAssign, |
| 7908 | bool AllowBothBool, bool AllowBoolConversion, |
| 7909 | bool AllowBoolOperation, bool ReportInvalid); |
| 7910 | |
| 7911 | /// Return a signed ext_vector_type that is of identical size and number of |
| 7912 | /// elements. For floating point vectors, return an integer type of identical |
| 7913 | /// size and number of elements. In the non ext_vector_type case, search from |
| 7914 | /// the largest type to the smallest type to avoid cases where long long == |
| 7915 | /// long, where long gets picked over long long. |
| 7916 | QualType GetSignedVectorType(QualType V); |
| 7917 | QualType GetSignedSizelessVectorType(QualType V); |
| 7918 | |
| 7919 | /// CheckVectorCompareOperands - vector comparisons are a clang extension that |
| 7920 | /// operates on extended vector types. Instead of producing an IntTy result, |
| 7921 | /// like a scalar comparison, a vector comparison produces a vector of integer |
| 7922 | /// types. |
| 7923 | QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, |
| 7924 | SourceLocation Loc, |
| 7925 | BinaryOperatorKind Opc); |
| 7926 | QualType CheckSizelessVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, |
| 7927 | SourceLocation Loc, |
| 7928 | BinaryOperatorKind Opc); |
| 7929 | QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS, |
| 7930 | SourceLocation Loc, |
| 7931 | BinaryOperatorKind Opc); |
| 7932 | QualType CheckMatrixLogicalOperands(ExprResult &LHS, ExprResult &RHS, |
| 7933 | SourceLocation Loc, |
| 7934 | BinaryOperatorKind Opc); |
| 7935 | // type checking for sizeless vector binary operators. |
| 7936 | QualType CheckSizelessVectorOperands(ExprResult &LHS, ExprResult &RHS, |
| 7937 | SourceLocation Loc, bool IsCompAssign, |
| 7938 | ArithConvKind OperationKind); |
| 7939 | |
| 7940 | /// Type checking for matrix binary operators. |
| 7941 | QualType CheckMatrixElementwiseOperands(ExprResult &LHS, ExprResult &RHS, |
| 7942 | SourceLocation Loc, |
| 7943 | bool IsCompAssign); |
| 7944 | QualType CheckMatrixMultiplyOperands(ExprResult &LHS, ExprResult &RHS, |
| 7945 | SourceLocation Loc, bool IsCompAssign); |
| 7946 | |
| 7947 | /// Are the two types SVE-bitcast-compatible types? I.e. is bitcasting from |
| 7948 | /// the first SVE type (e.g. an SVE VLAT) to the second type (e.g. an SVE |
| 7949 | /// VLST) allowed? |
| 7950 | /// |
| 7951 | /// This will also return false if the two given types do not make sense from |
| 7952 | /// the perspective of SVE bitcasts. |
| 7953 | bool isValidSveBitcast(QualType srcType, QualType destType); |
| 7954 | |
| 7955 | /// Are the two types matrix types and do they have the same dimensions i.e. |
| 7956 | /// do they have the same number of rows and the same number of columns? |
| 7957 | bool areMatrixTypesOfTheSameDimension(QualType srcTy, QualType destTy); |
| 7958 | |
| 7959 | bool areVectorTypesSameSize(QualType srcType, QualType destType); |
| 7960 | |
| 7961 | /// Are the two types lax-compatible vector types? That is, given |
| 7962 | /// that one of them is a vector, do they have equal storage sizes, |
| 7963 | /// where the storage size is the number of elements times the element |
| 7964 | /// size? |
| 7965 | /// |
| 7966 | /// This will also return false if either of the types is neither a |
| 7967 | /// vector nor a real type. |
| 7968 | bool areLaxCompatibleVectorTypes(QualType srcType, QualType destType); |
| 7969 | |
| 7970 | /// Is this a legal conversion between two types, one of which is |
| 7971 | /// known to be a vector type? |
| 7972 | bool isLaxVectorConversion(QualType srcType, QualType destType); |
| 7973 | |
| 7974 | // This returns true if at least one of the types is an altivec vector. |
| 7975 | bool anyAltivecTypes(QualType srcType, QualType destType); |
| 7976 | |
| 7977 | // type checking C++ declaration initializers (C++ [dcl.init]). |
| 7978 | |
| 7979 | /// Check a cast of an unknown-any type. We intentionally only |
| 7980 | /// trigger this for C-style casts. |
| 7981 | ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType, |
| 7982 | Expr *CastExpr, CastKind &CastKind, |
| 7983 | ExprValueKind &VK, CXXCastPath &Path); |
| 7984 | |
| 7985 | /// Force an expression with unknown-type to an expression of the |
| 7986 | /// given type. |
| 7987 | ExprResult forceUnknownAnyToType(Expr *E, QualType ToType); |
| 7988 | |
| 7989 | /// Type-check an expression that's being passed to an |
| 7990 | /// __unknown_anytype parameter. |
| 7991 | ExprResult checkUnknownAnyArg(SourceLocation callLoc, Expr *result, |
| 7992 | QualType ¶mType); |
| 7993 | |
| 7994 | // CheckMatrixCast - Check type constraints for matrix casts. |
| 7995 | // We allow casting between matrixes of the same dimensions i.e. when they |
| 7996 | // have the same number of rows and column. Returns true if the cast is |
| 7997 | // invalid. |
| 7998 | bool CheckMatrixCast(SourceRange R, QualType DestTy, QualType SrcTy, |
| 7999 | CastKind &Kind); |
| 8000 | |
| 8001 | // CheckVectorCast - check type constraints for vectors. |
| 8002 | // Since vectors are an extension, there are no C standard reference for this. |
| 8003 | // We allow casting between vectors and integer datatypes of the same size. |
| 8004 | // returns true if the cast is invalid |
| 8005 | bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, |
| 8006 | CastKind &Kind); |
| 8007 | |
| 8008 | /// Prepare `SplattedExpr` for a vector splat operation, adding |
| 8009 | /// implicit casts if necessary. |
| 8010 | ExprResult prepareVectorSplat(QualType VectorTy, Expr *SplattedExpr); |
| 8011 | |
| 8012 | /// Prepare `SplattedExpr` for a matrix splat operation, adding |
| 8013 | /// implicit casts if necessary. |
| 8014 | ExprResult prepareMatrixSplat(QualType MatrixTy, Expr *SplattedExpr); |
| 8015 | |
| 8016 | // CheckExtVectorCast - check type constraints for extended vectors. |
| 8017 | // Since vectors are an extension, there are no C standard reference for this. |
| 8018 | // We allow casting between vectors and integer datatypes of the same size, |
| 8019 | // or vectors and the element type of that vector. |
| 8020 | // returns the cast expr |
| 8021 | ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr, |
| 8022 | CastKind &Kind); |
| 8023 | |
| 8024 | QualType PreferredConditionType(ConditionKind K) const { |
| 8025 | return K == ConditionKind::Switch ? Context.IntTy : Context.BoolTy; |
| 8026 | } |
| 8027 | |
| 8028 | // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2), converts |
| 8029 | // functions and arrays to their respective pointers (C99 6.3.2.1), and |
| 8030 | // promotes floating-piont types according to the language semantics. |
| 8031 | ExprResult UsualUnaryConversions(Expr *E); |
| 8032 | |
| 8033 | // UsualUnaryFPConversions - promotes floating-point types according to the |
| 8034 | // current language semantics. |
| 8035 | ExprResult UsualUnaryFPConversions(Expr *E); |
| 8036 | |
| 8037 | /// CallExprUnaryConversions - a special case of an unary conversion |
| 8038 | /// performed on a function designator of a call expression. |
| 8039 | ExprResult CallExprUnaryConversions(Expr *E); |
| 8040 | |
| 8041 | // DefaultFunctionArrayConversion - converts functions and arrays |
| 8042 | // to their respective pointers (C99 6.3.2.1). |
| 8043 | ExprResult DefaultFunctionArrayConversion(Expr *E, bool Diagnose = true); |
| 8044 | |
| 8045 | // DefaultFunctionArrayLvalueConversion - converts functions and |
| 8046 | // arrays to their respective pointers and performs the |
| 8047 | // lvalue-to-rvalue conversion. |
| 8048 | ExprResult DefaultFunctionArrayLvalueConversion(Expr *E, |
| 8049 | bool Diagnose = true); |
| 8050 | |
| 8051 | // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on |
| 8052 | // the operand. This function is a no-op if the operand has a function type |
| 8053 | // or an array type. |
| 8054 | ExprResult DefaultLvalueConversion(Expr *E); |
| 8055 | |
| 8056 | // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that |
| 8057 | // do not have a prototype. Integer promotions are performed on each |
| 8058 | // argument, and arguments that have type float are promoted to double. |
| 8059 | ExprResult DefaultArgumentPromotion(Expr *E); |
| 8060 | |
| 8061 | VariadicCallType getVariadicCallType(FunctionDecl *FDecl, |
| 8062 | const FunctionProtoType *Proto, |
| 8063 | Expr *Fn); |
| 8064 | |
| 8065 | /// Determine the degree of POD-ness for an expression. |
| 8066 | /// Incomplete types are considered POD, since this check can be performed |
| 8067 | /// when we're in an unevaluated context. |
| 8068 | VarArgKind isValidVarArgType(const QualType &Ty); |
| 8069 | |
| 8070 | /// Check to see if the given expression is a valid argument to a variadic |
| 8071 | /// function, issuing a diagnostic if not. |
| 8072 | void checkVariadicArgument(const Expr *E, VariadicCallType CT); |
| 8073 | |
| 8074 | /// GatherArgumentsForCall - Collector argument expressions for various |
| 8075 | /// form of call prototypes. |
| 8076 | bool GatherArgumentsForCall( |
| 8077 | SourceLocation CallLoc, FunctionDecl *FDecl, |
| 8078 | const FunctionProtoType *Proto, unsigned FirstParam, |
| 8079 | ArrayRef<Expr *> Args, SmallVectorImpl<Expr *> &AllArgs, |
| 8080 | VariadicCallType CallType = VariadicCallType::DoesNotApply, |
| 8081 | bool AllowExplicit = false, bool IsListInitialization = false); |
| 8082 | |
| 8083 | // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but |
| 8084 | // will create a runtime trap if the resulting type is not a POD type. |
| 8085 | ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, |
| 8086 | FunctionDecl *FDecl); |
| 8087 | |
| 8088 | // Check that the usual arithmetic conversions can be performed on this pair |
| 8089 | // of expressions that might be of enumeration type. |
| 8090 | void checkEnumArithmeticConversions(Expr *LHS, Expr *RHS, SourceLocation Loc, |
| 8091 | ArithConvKind ACK); |
| 8092 | |
| 8093 | // UsualArithmeticConversions - performs the UsualUnaryConversions on it's |
| 8094 | // operands and then handles various conversions that are common to binary |
| 8095 | // operators (C99 6.3.1.8). If both operands aren't arithmetic, this |
| 8096 | // routine returns the first non-arithmetic type found. The client is |
| 8097 | // responsible for emitting appropriate error diagnostics. |
| 8098 | QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS, |
| 8099 | SourceLocation Loc, ArithConvKind ACK); |
| 8100 | |
| 8101 | bool IsAssignConvertCompatible(AssignConvertType ConvTy) { |
| 8102 | switch (ConvTy) { |
| 8103 | default: |
| 8104 | return false; |
| 8105 | case AssignConvertType::Compatible: |
| 8106 | case AssignConvertType::CompatiblePointerDiscardsQualifiers: |
| 8107 | case AssignConvertType::CompatibleVoidPtrToNonVoidPtr: |
| 8108 | return true; |
| 8109 | } |
| 8110 | llvm_unreachable("impossible" ); |
| 8111 | } |
| 8112 | |
| 8113 | /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the |
| 8114 | /// assignment conversion type specified by ConvTy. This returns true if the |
| 8115 | /// conversion was invalid or false if the conversion was accepted. |
| 8116 | bool DiagnoseAssignmentResult(AssignConvertType ConvTy, SourceLocation Loc, |
| 8117 | QualType DstType, QualType SrcType, |
| 8118 | Expr *SrcExpr, AssignmentAction Action, |
| 8119 | bool *Complained = nullptr); |
| 8120 | |
| 8121 | /// CheckAssignmentConstraints - Perform type checking for assignment, |
| 8122 | /// argument passing, variable initialization, and function return values. |
| 8123 | /// C99 6.5.16. |
| 8124 | AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, |
| 8125 | QualType LHSType, |
| 8126 | QualType RHSType); |
| 8127 | |
| 8128 | /// Check assignment constraints and optionally prepare for a conversion of |
| 8129 | /// the RHS to the LHS type. The conversion is prepared for if ConvertRHS |
| 8130 | /// is true. |
| 8131 | AssignConvertType CheckAssignmentConstraints(QualType LHSType, |
| 8132 | ExprResult &RHS, CastKind &Kind, |
| 8133 | bool ConvertRHS = true); |
| 8134 | |
| 8135 | /// Check assignment constraints for an assignment of RHS to LHSType. |
| 8136 | /// |
| 8137 | /// \param LHSType The destination type for the assignment. |
| 8138 | /// \param RHS The source expression for the assignment. |
| 8139 | /// \param Diagnose If \c true, diagnostics may be produced when checking |
| 8140 | /// for assignability. If a diagnostic is produced, \p RHS will be |
| 8141 | /// set to ExprError(). Note that this function may still return |
| 8142 | /// without producing a diagnostic, even for an invalid assignment. |
| 8143 | /// \param DiagnoseCFAudited If \c true, the target is a function parameter |
| 8144 | /// in an audited Core Foundation API and does not need to be checked |
| 8145 | /// for ARC retain issues. |
| 8146 | /// \param ConvertRHS If \c true, \p RHS will be updated to model the |
| 8147 | /// conversions necessary to perform the assignment. If \c false, |
| 8148 | /// \p Diagnose must also be \c false. |
| 8149 | AssignConvertType CheckSingleAssignmentConstraints( |
| 8150 | QualType LHSType, ExprResult &RHS, bool Diagnose = true, |
| 8151 | bool DiagnoseCFAudited = false, bool ConvertRHS = true); |
| 8152 | |
| 8153 | // If the lhs type is a transparent union, check whether we |
| 8154 | // can initialize the transparent union with the given expression. |
| 8155 | AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType, |
| 8156 | ExprResult &RHS); |
| 8157 | |
| 8158 | /// the following "Check" methods will return a valid/converted QualType |
| 8159 | /// or a null QualType (indicating an error diagnostic was issued). |
| 8160 | |
| 8161 | /// type checking binary operators (subroutines of CreateBuiltinBinOp). |
| 8162 | QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS, |
| 8163 | ExprResult &RHS); |
| 8164 | |
| 8165 | /// Diagnose cases where a scalar was implicitly converted to a vector and |
| 8166 | /// diagnose the underlying types. Otherwise, diagnose the error |
| 8167 | /// as invalid vector logical operands for non-C++ cases. |
| 8168 | QualType InvalidLogicalVectorOperands(SourceLocation Loc, ExprResult &LHS, |
| 8169 | ExprResult &RHS); |
| 8170 | |
| 8171 | QualType CheckMultiplyDivideOperands( // C99 6.5.5 |
| 8172 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
| 8173 | BinaryOperatorKind Opc); |
| 8174 | QualType CheckRemainderOperands( // C99 6.5.5 |
| 8175 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
| 8176 | bool IsCompAssign = false); |
| 8177 | QualType CheckAdditionOperands( // C99 6.5.6 |
| 8178 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
| 8179 | BinaryOperatorKind Opc, QualType *CompLHSTy = nullptr); |
| 8180 | QualType CheckSubtractionOperands( // C99 6.5.6 |
| 8181 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
| 8182 | BinaryOperatorKind Opc, QualType *CompLHSTy = nullptr); |
| 8183 | QualType CheckShiftOperands( // C99 6.5.7 |
| 8184 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
| 8185 | BinaryOperatorKind Opc, bool IsCompAssign = false); |
| 8186 | void CheckPtrComparisonWithNullChar(ExprResult &E, ExprResult &NullE); |
| 8187 | QualType CheckCompareOperands( // C99 6.5.8/9 |
| 8188 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
| 8189 | BinaryOperatorKind Opc); |
| 8190 | QualType CheckBitwiseOperands( // C99 6.5.[10...12] |
| 8191 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
| 8192 | BinaryOperatorKind Opc); |
| 8193 | QualType CheckLogicalOperands( // C99 6.5.[13,14] |
| 8194 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
| 8195 | BinaryOperatorKind Opc); |
| 8196 | // CheckAssignmentOperands is used for both simple and compound assignment. |
| 8197 | // For simple assignment, pass both expressions and a null converted type. |
| 8198 | // For compound assignment, pass both expressions and the converted type. |
| 8199 | QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] |
| 8200 | Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType, |
| 8201 | BinaryOperatorKind Opc); |
| 8202 | |
| 8203 | /// To be used for checking whether the arguments being passed to |
| 8204 | /// function exceeds the number of parameters expected for it. |
| 8205 | static bool TooManyArguments(size_t NumParams, size_t NumArgs, |
| 8206 | bool PartialOverloading = false) { |
| 8207 | // We check whether we're just after a comma in code-completion. |
| 8208 | if (NumArgs > 0 && PartialOverloading) |
| 8209 | return NumArgs + 1 > NumParams; // If so, we view as an extra argument. |
| 8210 | return NumArgs > NumParams; |
| 8211 | } |
| 8212 | |
| 8213 | /// Whether the AST is currently being rebuilt to correct immediate |
| 8214 | /// invocations. Immediate invocation candidates and references to consteval |
| 8215 | /// functions aren't tracked when this is set. |
| 8216 | bool RebuildingImmediateInvocation = false; |
| 8217 | |
| 8218 | bool isAlwaysConstantEvaluatedContext() const { |
| 8219 | const ExpressionEvaluationContextRecord &Ctx = currentEvaluationContext(); |
| 8220 | return (Ctx.isConstantEvaluated() || isConstantEvaluatedOverride) && |
| 8221 | !Ctx.InConditionallyConstantEvaluateContext; |
| 8222 | } |
| 8223 | |
| 8224 | /// Determines whether we are currently in a context that |
| 8225 | /// is not evaluated as per C++ [expr] p5. |
| 8226 | bool isUnevaluatedContext() const { |
| 8227 | return currentEvaluationContext().isUnevaluated(); |
| 8228 | } |
| 8229 | |
| 8230 | bool isImmediateFunctionContext() const { |
| 8231 | return currentEvaluationContext().isImmediateFunctionContext(); |
| 8232 | } |
| 8233 | |
| 8234 | bool isInLifetimeExtendingContext() const { |
| 8235 | return currentEvaluationContext().InLifetimeExtendingContext; |
| 8236 | } |
| 8237 | |
| 8238 | bool needsRebuildOfDefaultArgOrInit() const { |
| 8239 | return currentEvaluationContext().RebuildDefaultArgOrDefaultInit; |
| 8240 | } |
| 8241 | |
| 8242 | bool isCheckingDefaultArgumentOrInitializer() const { |
| 8243 | const ExpressionEvaluationContextRecord &Ctx = currentEvaluationContext(); |
| 8244 | return (Ctx.Context == |
| 8245 | ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed) || |
| 8246 | Ctx.IsCurrentlyCheckingDefaultArgumentOrInitializer; |
| 8247 | } |
| 8248 | |
| 8249 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> |
| 8250 | InnermostDeclarationWithDelayedImmediateInvocations() const { |
| 8251 | assert(!ExprEvalContexts.empty() && |
| 8252 | "Must be in an expression evaluation context" ); |
| 8253 | for (const auto &Ctx : llvm::reverse(C: ExprEvalContexts)) { |
| 8254 | if (Ctx.Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
| 8255 | Ctx.DelayedDefaultInitializationContext) |
| 8256 | return Ctx.DelayedDefaultInitializationContext; |
| 8257 | if (Ctx.isConstantEvaluated() || Ctx.isImmediateFunctionContext() || |
| 8258 | Ctx.isUnevaluated()) |
| 8259 | break; |
| 8260 | } |
| 8261 | return std::nullopt; |
| 8262 | } |
| 8263 | |
| 8264 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> |
| 8265 | OutermostDeclarationWithDelayedImmediateInvocations() const { |
| 8266 | assert(!ExprEvalContexts.empty() && |
| 8267 | "Must be in an expression evaluation context" ); |
| 8268 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> Res; |
| 8269 | for (auto &Ctx : llvm::reverse(C: ExprEvalContexts)) { |
| 8270 | if (Ctx.Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
| 8271 | !Ctx.DelayedDefaultInitializationContext && Res) |
| 8272 | break; |
| 8273 | if (Ctx.isConstantEvaluated() || Ctx.isImmediateFunctionContext() || |
| 8274 | Ctx.isUnevaluated()) |
| 8275 | break; |
| 8276 | Res = Ctx.DelayedDefaultInitializationContext; |
| 8277 | } |
| 8278 | return Res; |
| 8279 | } |
| 8280 | |
| 8281 | DefaultedComparisonKind getDefaultedComparisonKind(const FunctionDecl *FD) { |
| 8282 | return getDefaultedFunctionKind(FD).asComparison(); |
| 8283 | } |
| 8284 | |
| 8285 | /// Returns a field in a CXXRecordDecl that has the same name as the decl \p |
| 8286 | /// SelfAssigned when inside a CXXMethodDecl. |
| 8287 | const FieldDecl * |
| 8288 | getSelfAssignmentClassMemberCandidate(const ValueDecl *SelfAssigned); |
| 8289 | |
| 8290 | void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D); |
| 8291 | |
| 8292 | template <typename... Ts> |
| 8293 | bool RequireCompleteSizedType(SourceLocation Loc, QualType T, unsigned DiagID, |
| 8294 | const Ts &...Args) { |
| 8295 | SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
| 8296 | return RequireCompleteType(Loc, T, CompleteTypeKind::Normal, Diagnoser); |
| 8297 | } |
| 8298 | |
| 8299 | template <typename... Ts> |
| 8300 | bool RequireCompleteSizedExprType(Expr *E, unsigned DiagID, |
| 8301 | const Ts &...Args) { |
| 8302 | SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
| 8303 | return RequireCompleteExprType(E, CompleteTypeKind::Normal, Diagnoser); |
| 8304 | } |
| 8305 | |
| 8306 | /// Abstract class used to diagnose incomplete types. |
| 8307 | struct TypeDiagnoser { |
| 8308 | TypeDiagnoser() {} |
| 8309 | |
| 8310 | virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0; |
| 8311 | virtual ~TypeDiagnoser() {} |
| 8312 | }; |
| 8313 | |
| 8314 | template <typename... Ts> class BoundTypeDiagnoser : public TypeDiagnoser { |
| 8315 | protected: |
| 8316 | unsigned DiagID; |
| 8317 | std::tuple<const Ts &...> Args; |
| 8318 | |
| 8319 | template <std::size_t... Is> |
| 8320 | void emit(const SemaDiagnosticBuilder &DB, |
| 8321 | std::index_sequence<Is...>) const { |
| 8322 | // Apply all tuple elements to the builder in order. |
| 8323 | bool Dummy[] = {false, (DB << getPrintable(std::get<Is>(Args)))...}; |
| 8324 | (void)Dummy; |
| 8325 | } |
| 8326 | |
| 8327 | public: |
| 8328 | BoundTypeDiagnoser(unsigned DiagID, const Ts &...Args) |
| 8329 | : TypeDiagnoser(), DiagID(DiagID), Args(Args...) { |
| 8330 | assert(DiagID != 0 && "no diagnostic for type diagnoser" ); |
| 8331 | } |
| 8332 | |
| 8333 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
| 8334 | const SemaDiagnosticBuilder &DB = S.Diag(Loc, DiagID); |
| 8335 | emit(DB, std::index_sequence_for<Ts...>()); |
| 8336 | DB << T; |
| 8337 | } |
| 8338 | }; |
| 8339 | |
| 8340 | /// A derivative of BoundTypeDiagnoser for which the diagnostic's type |
| 8341 | /// parameter is preceded by a 0/1 enum that is 1 if the type is sizeless. |
| 8342 | /// For example, a diagnostic with no other parameters would generally have |
| 8343 | /// the form "...%select{incomplete|sizeless}0 type %1...". |
| 8344 | template <typename... Ts> |
| 8345 | class SizelessTypeDiagnoser : public BoundTypeDiagnoser<Ts...> { |
| 8346 | public: |
| 8347 | SizelessTypeDiagnoser(unsigned DiagID, const Ts &...Args) |
| 8348 | : BoundTypeDiagnoser<Ts...>(DiagID, Args...) {} |
| 8349 | |
| 8350 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
| 8351 | const SemaDiagnosticBuilder &DB = S.Diag(Loc, this->DiagID); |
| 8352 | this->emit(DB, std::index_sequence_for<Ts...>()); |
| 8353 | DB << T->isSizelessType() << T; |
| 8354 | } |
| 8355 | }; |
| 8356 | |
| 8357 | /// Check an argument list for placeholders that we won't try to |
| 8358 | /// handle later. |
| 8359 | bool CheckArgsForPlaceholders(MultiExprArg args); |
| 8360 | |
| 8361 | /// The C++ "std::source_location::__impl" struct, defined in |
| 8362 | /// \<source_location>. |
| 8363 | RecordDecl *StdSourceLocationImplDecl; |
| 8364 | |
| 8365 | /// A stack of expression evaluation contexts. |
| 8366 | SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts; |
| 8367 | |
| 8368 | // Set of failed immediate invocations to avoid double diagnosing. |
| 8369 | llvm::SmallPtrSet<ConstantExpr *, 4> FailedImmediateInvocations; |
| 8370 | |
| 8371 | /// List of SourceLocations where 'self' is implicitly retained inside a |
| 8372 | /// block. |
| 8373 | llvm::SmallVector<std::pair<SourceLocation, const BlockDecl *>, 1> |
| 8374 | ImplicitlyRetainedSelfLocs; |
| 8375 | |
| 8376 | /// Do an explicit extend of the given block pointer if we're in ARC. |
| 8377 | void maybeExtendBlockObject(ExprResult &E); |
| 8378 | |
| 8379 | std::vector<std::pair<QualType, unsigned>> ExcessPrecisionNotSatisfied; |
| 8380 | SourceLocation LocationOfExcessPrecisionNotSatisfied; |
| 8381 | void DiagnosePrecisionLossInComplexDivision(); |
| 8382 | |
| 8383 | private: |
| 8384 | static BinaryOperatorKind ConvertTokenKindToBinaryOpcode(tok::TokenKind Kind); |
| 8385 | |
| 8386 | /// Methods for marking which expressions involve dereferencing a pointer |
| 8387 | /// marked with the 'noderef' attribute. Expressions are checked bottom up as |
| 8388 | /// they are parsed, meaning that a noderef pointer may not be accessed. For |
| 8389 | /// example, in `&*p` where `p` is a noderef pointer, we will first parse the |
| 8390 | /// `*p`, but need to check that `address of` is called on it. This requires |
| 8391 | /// keeping a container of all pending expressions and checking if the address |
| 8392 | /// of them are eventually taken. |
| 8393 | void CheckSubscriptAccessOfNoDeref(const ArraySubscriptExpr *E); |
| 8394 | void CheckAddressOfNoDeref(const Expr *E); |
| 8395 | |
| 8396 | ///@} |
| 8397 | |
| 8398 | // |
| 8399 | // |
| 8400 | // ------------------------------------------------------------------------- |
| 8401 | // |
| 8402 | // |
| 8403 | |
| 8404 | /// \name C++ Expressions |
| 8405 | /// Implementations are in SemaExprCXX.cpp |
| 8406 | ///@{ |
| 8407 | |
| 8408 | public: |
| 8409 | /// The C++ "std::bad_alloc" class, which is defined by the C++ |
| 8410 | /// standard library. |
| 8411 | LazyDeclPtr StdBadAlloc; |
| 8412 | |
| 8413 | /// The C++ "std::align_val_t" enum class, which is defined by the C++ |
| 8414 | /// standard library. |
| 8415 | LazyDeclPtr StdAlignValT; |
| 8416 | |
| 8417 | /// The C++ "type_info" declaration, which is defined in \<typeinfo>. |
| 8418 | RecordDecl *CXXTypeInfoDecl; |
| 8419 | |
| 8420 | /// A flag to remember whether the implicit forms of operator new and delete |
| 8421 | /// have been declared. |
| 8422 | bool GlobalNewDeleteDeclared; |
| 8423 | |
| 8424 | /// Delete-expressions to be analyzed at the end of translation unit |
| 8425 | /// |
| 8426 | /// This list contains class members, and locations of delete-expressions |
| 8427 | /// that could not be proven as to whether they mismatch with new-expression |
| 8428 | /// used in initializer of the field. |
| 8429 | llvm::MapVector<FieldDecl *, DeleteLocs> DeleteExprs; |
| 8430 | |
| 8431 | /// Handle the result of the special case name lookup for inheriting |
| 8432 | /// constructor declarations. 'NS::X::X' and 'NS::X<...>::X' are treated as |
| 8433 | /// constructor names in member using declarations, even if 'X' is not the |
| 8434 | /// name of the corresponding type. |
| 8435 | ParsedType getInheritingConstructorName(CXXScopeSpec &SS, |
| 8436 | SourceLocation NameLoc, |
| 8437 | const IdentifierInfo &Name); |
| 8438 | |
| 8439 | ParsedType getConstructorName(const IdentifierInfo &II, |
| 8440 | SourceLocation NameLoc, Scope *S, |
| 8441 | CXXScopeSpec &SS, bool EnteringContext); |
| 8442 | ParsedType getDestructorName(const IdentifierInfo &II, SourceLocation NameLoc, |
| 8443 | Scope *S, CXXScopeSpec &SS, |
| 8444 | ParsedType ObjectType, bool EnteringContext); |
| 8445 | |
| 8446 | ParsedType getDestructorTypeForDecltype(const DeclSpec &DS, |
| 8447 | ParsedType ObjectType); |
| 8448 | |
| 8449 | /// Build a C++ typeid expression with a type operand. |
| 8450 | ExprResult BuildCXXTypeId(QualType TypeInfoType, SourceLocation TypeidLoc, |
| 8451 | TypeSourceInfo *Operand, SourceLocation RParenLoc); |
| 8452 | |
| 8453 | /// Build a C++ typeid expression with an expression operand. |
| 8454 | ExprResult BuildCXXTypeId(QualType TypeInfoType, SourceLocation TypeidLoc, |
| 8455 | Expr *Operand, SourceLocation RParenLoc); |
| 8456 | |
| 8457 | /// ActOnCXXTypeid - Parse typeid( something ). |
| 8458 | ExprResult ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc, |
| 8459 | bool isType, void *TyOrExpr, |
| 8460 | SourceLocation RParenLoc); |
| 8461 | |
| 8462 | /// Build a Microsoft __uuidof expression with a type operand. |
| 8463 | ExprResult BuildCXXUuidof(QualType TypeInfoType, SourceLocation TypeidLoc, |
| 8464 | TypeSourceInfo *Operand, SourceLocation RParenLoc); |
| 8465 | |
| 8466 | /// Build a Microsoft __uuidof expression with an expression operand. |
| 8467 | ExprResult BuildCXXUuidof(QualType TypeInfoType, SourceLocation TypeidLoc, |
| 8468 | Expr *Operand, SourceLocation RParenLoc); |
| 8469 | |
| 8470 | /// ActOnCXXUuidof - Parse __uuidof( something ). |
| 8471 | ExprResult ActOnCXXUuidof(SourceLocation OpLoc, SourceLocation LParenLoc, |
| 8472 | bool isType, void *TyOrExpr, |
| 8473 | SourceLocation RParenLoc); |
| 8474 | |
| 8475 | //// ActOnCXXThis - Parse 'this' pointer. |
| 8476 | ExprResult ActOnCXXThis(SourceLocation Loc); |
| 8477 | |
| 8478 | /// Check whether the type of 'this' is valid in the current context. |
| 8479 | bool CheckCXXThisType(SourceLocation Loc, QualType Type); |
| 8480 | |
| 8481 | /// Build a CXXThisExpr and mark it referenced in the current context. |
| 8482 | Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit); |
| 8483 | void MarkThisReferenced(CXXThisExpr *This); |
| 8484 | |
| 8485 | /// Try to retrieve the type of the 'this' pointer. |
| 8486 | /// |
| 8487 | /// \returns The type of 'this', if possible. Otherwise, returns a NULL type. |
| 8488 | QualType getCurrentThisType(); |
| 8489 | |
| 8490 | /// When non-NULL, the C++ 'this' expression is allowed despite the |
| 8491 | /// current context not being a non-static member function. In such cases, |
| 8492 | /// this provides the type used for 'this'. |
| 8493 | QualType CXXThisTypeOverride; |
| 8494 | |
| 8495 | /// RAII object used to temporarily allow the C++ 'this' expression |
| 8496 | /// to be used, with the given qualifiers on the current class type. |
| 8497 | class CXXThisScopeRAII { |
| 8498 | Sema &S; |
| 8499 | QualType OldCXXThisTypeOverride; |
| 8500 | bool Enabled; |
| 8501 | |
| 8502 | public: |
| 8503 | /// Introduce a new scope where 'this' may be allowed (when enabled), |
| 8504 | /// using the given declaration (which is either a class template or a |
| 8505 | /// class) along with the given qualifiers. |
| 8506 | /// along with the qualifiers placed on '*this'. |
| 8507 | CXXThisScopeRAII(Sema &S, Decl *ContextDecl, Qualifiers CXXThisTypeQuals, |
| 8508 | bool Enabled = true); |
| 8509 | |
| 8510 | ~CXXThisScopeRAII(); |
| 8511 | CXXThisScopeRAII(const CXXThisScopeRAII &) = delete; |
| 8512 | CXXThisScopeRAII &operator=(const CXXThisScopeRAII &) = delete; |
| 8513 | }; |
| 8514 | |
| 8515 | /// Make sure the value of 'this' is actually available in the current |
| 8516 | /// context, if it is a potentially evaluated context. |
| 8517 | /// |
| 8518 | /// \param Loc The location at which the capture of 'this' occurs. |
| 8519 | /// |
| 8520 | /// \param Explicit Whether 'this' is explicitly captured in a lambda |
| 8521 | /// capture list. |
| 8522 | /// |
| 8523 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
| 8524 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
| 8525 | /// This is useful when enclosing lambdas must speculatively capture |
| 8526 | /// 'this' that may or may not be used in certain specializations of |
| 8527 | /// a nested generic lambda (depending on whether the name resolves to |
| 8528 | /// a non-static member function or a static function). |
| 8529 | /// \return returns 'true' if failed, 'false' if success. |
| 8530 | bool CheckCXXThisCapture( |
| 8531 | SourceLocation Loc, bool Explicit = false, bool BuildAndDiagnose = true, |
| 8532 | const unsigned *const FunctionScopeIndexToStopAt = nullptr, |
| 8533 | bool ByCopy = false); |
| 8534 | |
| 8535 | /// Determine whether the given type is the type of *this that is used |
| 8536 | /// outside of the body of a member function for a type that is currently |
| 8537 | /// being defined. |
| 8538 | bool isThisOutsideMemberFunctionBody(QualType BaseType); |
| 8539 | |
| 8540 | /// ActOnCXXBoolLiteral - Parse {true,false} literals. |
| 8541 | ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); |
| 8542 | |
| 8543 | /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. |
| 8544 | ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); |
| 8545 | |
| 8546 | //// ActOnCXXThrow - Parse throw expressions. |
| 8547 | ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr); |
| 8548 | ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, |
| 8549 | bool IsThrownVarInScope); |
| 8550 | |
| 8551 | /// CheckCXXThrowOperand - Validate the operand of a throw. |
| 8552 | bool CheckCXXThrowOperand(SourceLocation ThrowLoc, QualType ThrowTy, Expr *E); |
| 8553 | |
| 8554 | /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. |
| 8555 | /// Can be interpreted either as function-style casting ("int(x)") |
| 8556 | /// or class type construction ("ClassType(x,y,z)") |
| 8557 | /// or creation of a value-initialized type ("int()"). |
| 8558 | ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, |
| 8559 | SourceLocation LParenOrBraceLoc, |
| 8560 | MultiExprArg Exprs, |
| 8561 | SourceLocation RParenOrBraceLoc, |
| 8562 | bool ListInitialization); |
| 8563 | |
| 8564 | ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, |
| 8565 | SourceLocation LParenLoc, |
| 8566 | MultiExprArg Exprs, |
| 8567 | SourceLocation RParenLoc, |
| 8568 | bool ListInitialization); |
| 8569 | |
| 8570 | /// Parsed a C++ 'new' expression (C++ 5.3.4). |
| 8571 | /// |
| 8572 | /// E.g.: |
| 8573 | /// @code new (memory) int[size][4] @endcode |
| 8574 | /// or |
| 8575 | /// @code ::new Foo(23, "hello") @endcode |
| 8576 | /// |
| 8577 | /// \param StartLoc The first location of the expression. |
| 8578 | /// \param UseGlobal True if 'new' was prefixed with '::'. |
| 8579 | /// \param PlacementLParen Opening paren of the placement arguments. |
| 8580 | /// \param PlacementArgs Placement new arguments. |
| 8581 | /// \param PlacementRParen Closing paren of the placement arguments. |
| 8582 | /// \param TypeIdParens If the type is in parens, the source range. |
| 8583 | /// \param D The type to be allocated, as well as array dimensions. |
| 8584 | /// \param Initializer The initializing expression or initializer-list, or |
| 8585 | /// null if there is none. |
| 8586 | ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, |
| 8587 | SourceLocation PlacementLParen, |
| 8588 | MultiExprArg PlacementArgs, |
| 8589 | SourceLocation PlacementRParen, |
| 8590 | SourceRange TypeIdParens, Declarator &D, |
| 8591 | Expr *Initializer); |
| 8592 | ExprResult |
| 8593 | BuildCXXNew(SourceRange Range, bool UseGlobal, SourceLocation PlacementLParen, |
| 8594 | MultiExprArg PlacementArgs, SourceLocation PlacementRParen, |
| 8595 | SourceRange TypeIdParens, QualType AllocType, |
| 8596 | TypeSourceInfo *AllocTypeInfo, std::optional<Expr *> ArraySize, |
| 8597 | SourceRange DirectInitRange, Expr *Initializer); |
| 8598 | |
| 8599 | /// Determine whether \p FD is an aligned allocation or deallocation |
| 8600 | /// function that is unavailable. |
| 8601 | bool isUnavailableAlignedAllocationFunction(const FunctionDecl &FD) const; |
| 8602 | |
| 8603 | /// Produce diagnostics if \p FD is an aligned allocation or deallocation |
| 8604 | /// function that is unavailable. |
| 8605 | void diagnoseUnavailableAlignedAllocation(const FunctionDecl &FD, |
| 8606 | SourceLocation Loc); |
| 8607 | |
| 8608 | /// Checks that a type is suitable as the allocated type |
| 8609 | /// in a new-expression. |
| 8610 | bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, |
| 8611 | SourceRange R); |
| 8612 | |
| 8613 | /// Finds the overloads of operator new and delete that are appropriate |
| 8614 | /// for the allocation. |
| 8615 | bool FindAllocationFunctions( |
| 8616 | SourceLocation StartLoc, SourceRange Range, |
| 8617 | AllocationFunctionScope NewScope, AllocationFunctionScope DeleteScope, |
| 8618 | QualType AllocType, bool IsArray, ImplicitAllocationParameters &IAP, |
| 8619 | MultiExprArg PlaceArgs, FunctionDecl *&OperatorNew, |
| 8620 | FunctionDecl *&OperatorDelete, bool Diagnose = true); |
| 8621 | |
| 8622 | /// DeclareGlobalNewDelete - Declare the global forms of operator new and |
| 8623 | /// delete. These are: |
| 8624 | /// @code |
| 8625 | /// // C++03: |
| 8626 | /// void* operator new(std::size_t) throw(std::bad_alloc); |
| 8627 | /// void* operator new[](std::size_t) throw(std::bad_alloc); |
| 8628 | /// void operator delete(void *) throw(); |
| 8629 | /// void operator delete[](void *) throw(); |
| 8630 | /// // C++11: |
| 8631 | /// void* operator new(std::size_t); |
| 8632 | /// void* operator new[](std::size_t); |
| 8633 | /// void operator delete(void *) noexcept; |
| 8634 | /// void operator delete[](void *) noexcept; |
| 8635 | /// // C++1y: |
| 8636 | /// void* operator new(std::size_t); |
| 8637 | /// void* operator new[](std::size_t); |
| 8638 | /// void operator delete(void *) noexcept; |
| 8639 | /// void operator delete[](void *) noexcept; |
| 8640 | /// void operator delete(void *, std::size_t) noexcept; |
| 8641 | /// void operator delete[](void *, std::size_t) noexcept; |
| 8642 | /// @endcode |
| 8643 | /// Note that the placement and nothrow forms of new are *not* implicitly |
| 8644 | /// declared. Their use requires including \<new\>. |
| 8645 | void DeclareGlobalNewDelete(); |
| 8646 | void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, |
| 8647 | ArrayRef<QualType> Params); |
| 8648 | |
| 8649 | bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, |
| 8650 | DeclarationName Name, FunctionDecl *&Operator, |
| 8651 | ImplicitDeallocationParameters, |
| 8652 | bool Diagnose = true); |
| 8653 | FunctionDecl *FindUsualDeallocationFunction(SourceLocation StartLoc, |
| 8654 | ImplicitDeallocationParameters, |
| 8655 | DeclarationName Name, |
| 8656 | bool Diagnose = true); |
| 8657 | FunctionDecl *FindDeallocationFunctionForDestructor(SourceLocation StartLoc, |
| 8658 | CXXRecordDecl *RD, |
| 8659 | bool Diagnose, |
| 8660 | bool LookForGlobal, |
| 8661 | DeclarationName Name); |
| 8662 | |
| 8663 | /// ActOnCXXDelete - Parsed a C++ 'delete' expression (C++ 5.3.5), as in: |
| 8664 | /// @code ::delete ptr; @endcode |
| 8665 | /// or |
| 8666 | /// @code delete [] ptr; @endcode |
| 8667 | ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, |
| 8668 | bool ArrayForm, Expr *Operand); |
| 8669 | void CheckVirtualDtorCall(CXXDestructorDecl *dtor, SourceLocation Loc, |
| 8670 | bool IsDelete, bool CallCanBeVirtual, |
| 8671 | bool WarnOnNonAbstractTypes, |
| 8672 | SourceLocation DtorLoc); |
| 8673 | |
| 8674 | ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, |
| 8675 | Expr *Operand, SourceLocation RParen); |
| 8676 | ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, |
| 8677 | SourceLocation RParen); |
| 8678 | |
| 8679 | ExprResult ActOnStartCXXMemberReference(Scope *S, Expr *Base, |
| 8680 | SourceLocation OpLoc, |
| 8681 | tok::TokenKind OpKind, |
| 8682 | ParsedType &ObjectType, |
| 8683 | bool &MayBePseudoDestructor); |
| 8684 | |
| 8685 | ExprResult BuildPseudoDestructorExpr( |
| 8686 | Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, |
| 8687 | const CXXScopeSpec &SS, TypeSourceInfo *ScopeType, SourceLocation CCLoc, |
| 8688 | SourceLocation TildeLoc, PseudoDestructorTypeStorage DestroyedType); |
| 8689 | |
| 8690 | ExprResult ActOnPseudoDestructorExpr( |
| 8691 | Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, |
| 8692 | CXXScopeSpec &SS, UnqualifiedId &FirstTypeName, SourceLocation CCLoc, |
| 8693 | SourceLocation TildeLoc, UnqualifiedId &SecondTypeName); |
| 8694 | |
| 8695 | ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, |
| 8696 | SourceLocation OpLoc, |
| 8697 | tok::TokenKind OpKind, |
| 8698 | SourceLocation TildeLoc, |
| 8699 | const DeclSpec &DS); |
| 8700 | |
| 8701 | /// MaybeCreateExprWithCleanups - If the current full-expression |
| 8702 | /// requires any cleanups, surround it with a ExprWithCleanups node. |
| 8703 | /// Otherwise, just returns the passed-in expression. |
| 8704 | Expr *MaybeCreateExprWithCleanups(Expr *SubExpr); |
| 8705 | Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt); |
| 8706 | ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr); |
| 8707 | |
| 8708 | ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue) { |
| 8709 | return ActOnFinishFullExpr( |
| 8710 | Expr, CC: Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue); |
| 8711 | } |
| 8712 | ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC, |
| 8713 | bool DiscardedValue, bool IsConstexpr = false, |
| 8714 | bool IsTemplateArgument = false); |
| 8715 | StmtResult ActOnFinishFullStmt(Stmt *Stmt); |
| 8716 | |
| 8717 | /// Process the expression contained within a decltype. For such expressions, |
| 8718 | /// certain semantic checks on temporaries are delayed until this point, and |
| 8719 | /// are omitted for the 'topmost' call in the decltype expression. If the |
| 8720 | /// topmost call bound a temporary, strip that temporary off the expression. |
| 8721 | ExprResult ActOnDecltypeExpression(Expr *E); |
| 8722 | |
| 8723 | bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id, |
| 8724 | bool IsUDSuffix); |
| 8725 | |
| 8726 | bool isUsualDeallocationFunction(const CXXMethodDecl *FD); |
| 8727 | |
| 8728 | ConditionResult ActOnConditionVariable(Decl *ConditionVar, |
| 8729 | SourceLocation StmtLoc, |
| 8730 | ConditionKind CK); |
| 8731 | |
| 8732 | /// Check the use of the given variable as a C++ condition in an if, |
| 8733 | /// while, do-while, or switch statement. |
| 8734 | ExprResult CheckConditionVariable(VarDecl *ConditionVar, |
| 8735 | SourceLocation StmtLoc, ConditionKind CK); |
| 8736 | |
| 8737 | /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. |
| 8738 | ExprResult CheckCXXBooleanCondition(Expr *CondExpr, bool IsConstexpr = false); |
| 8739 | |
| 8740 | /// Helper function to determine whether this is the (deprecated) C++ |
| 8741 | /// conversion from a string literal to a pointer to non-const char or |
| 8742 | /// non-const wchar_t (for narrow and wide string literals, |
| 8743 | /// respectively). |
| 8744 | bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); |
| 8745 | |
| 8746 | /// PerformImplicitConversion - Perform an implicit conversion of the |
| 8747 | /// expression From to the type ToType using the pre-computed implicit |
| 8748 | /// conversion sequence ICS. Returns the converted |
| 8749 | /// expression. Action is the kind of conversion we're performing, |
| 8750 | /// used in the error message. |
| 8751 | ExprResult PerformImplicitConversion( |
| 8752 | Expr *From, QualType ToType, const ImplicitConversionSequence &ICS, |
| 8753 | AssignmentAction Action, |
| 8754 | CheckedConversionKind CCK = CheckedConversionKind::Implicit); |
| 8755 | |
| 8756 | /// PerformImplicitConversion - Perform an implicit conversion of the |
| 8757 | /// expression From to the type ToType by following the standard |
| 8758 | /// conversion sequence SCS. Returns the converted |
| 8759 | /// expression. Flavor is the context in which we're performing this |
| 8760 | /// conversion, for use in error messages. |
| 8761 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
| 8762 | const StandardConversionSequence &SCS, |
| 8763 | AssignmentAction Action, |
| 8764 | CheckedConversionKind CCK); |
| 8765 | |
| 8766 | bool CheckTypeTraitArity(unsigned Arity, SourceLocation Loc, size_t N); |
| 8767 | |
| 8768 | /// Parsed one of the type trait support pseudo-functions. |
| 8769 | ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc, |
| 8770 | ArrayRef<ParsedType> Args, |
| 8771 | SourceLocation RParenLoc); |
| 8772 | ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, |
| 8773 | ArrayRef<TypeSourceInfo *> Args, |
| 8774 | SourceLocation RParenLoc); |
| 8775 | |
| 8776 | /// ActOnArrayTypeTrait - Parsed one of the binary type trait support |
| 8777 | /// pseudo-functions. |
| 8778 | ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, SourceLocation KWLoc, |
| 8779 | ParsedType LhsTy, Expr *DimExpr, |
| 8780 | SourceLocation RParen); |
| 8781 | |
| 8782 | ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, SourceLocation KWLoc, |
| 8783 | TypeSourceInfo *TSInfo, Expr *DimExpr, |
| 8784 | SourceLocation RParen); |
| 8785 | |
| 8786 | /// ActOnExpressionTrait - Parsed one of the unary type trait support |
| 8787 | /// pseudo-functions. |
| 8788 | ExprResult ActOnExpressionTrait(ExpressionTrait OET, SourceLocation KWLoc, |
| 8789 | Expr *Queried, SourceLocation RParen); |
| 8790 | |
| 8791 | ExprResult BuildExpressionTrait(ExpressionTrait OET, SourceLocation KWLoc, |
| 8792 | Expr *Queried, SourceLocation RParen); |
| 8793 | |
| 8794 | QualType CheckPointerToMemberOperands( // C++ 5.5 |
| 8795 | ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, SourceLocation OpLoc, |
| 8796 | bool isIndirect); |
| 8797 | QualType CheckVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS, |
| 8798 | ExprResult &RHS, |
| 8799 | SourceLocation QuestionLoc); |
| 8800 | |
| 8801 | //// Determines if a type is trivially relocatable |
| 8802 | /// according to the C++26 rules. |
| 8803 | // FIXME: This is in Sema because it requires |
| 8804 | // overload resolution, can we move to ASTContext? |
| 8805 | bool IsCXXTriviallyRelocatableType(QualType T); |
| 8806 | bool IsCXXTriviallyRelocatableType(const CXXRecordDecl &RD); |
| 8807 | |
| 8808 | /// Check the operands of ?: under C++ semantics. |
| 8809 | /// |
| 8810 | /// See C++ [expr.cond]. Note that LHS is never null, even for the GNU x ?: y |
| 8811 | /// extension. In this case, LHS == Cond. (But they're not aliases.) |
| 8812 | /// |
| 8813 | /// This function also implements GCC's vector extension and the |
| 8814 | /// OpenCL/ext_vector_type extension for conditionals. The vector extensions |
| 8815 | /// permit the use of a?b:c where the type of a is that of a integer vector |
| 8816 | /// with the same number of elements and size as the vectors of b and c. If |
| 8817 | /// one of either b or c is a scalar it is implicitly converted to match the |
| 8818 | /// type of the vector. Otherwise the expression is ill-formed. If both b and |
| 8819 | /// c are scalars, then b and c are checked and converted to the type of a if |
| 8820 | /// possible. |
| 8821 | /// |
| 8822 | /// The expressions are evaluated differently for GCC's and OpenCL's |
| 8823 | /// extensions. For the GCC extension, the ?: operator is evaluated as |
| 8824 | /// (a[0] != 0 ? b[0] : c[0], .. , a[n] != 0 ? b[n] : c[n]). |
| 8825 | /// For the OpenCL extensions, the ?: operator is evaluated as |
| 8826 | /// (most-significant-bit-set(a[0]) ? b[0] : c[0], .. , |
| 8827 | /// most-significant-bit-set(a[n]) ? b[n] : c[n]). |
| 8828 | QualType CXXCheckConditionalOperands( // C++ 5.16 |
| 8829 | ExprResult &cond, ExprResult &lhs, ExprResult &rhs, ExprValueKind &VK, |
| 8830 | ExprObjectKind &OK, SourceLocation questionLoc); |
| 8831 | |
| 8832 | /// Find a merged pointer type and convert the two expressions to it. |
| 8833 | /// |
| 8834 | /// This finds the composite pointer type for \p E1 and \p E2 according to |
| 8835 | /// C++2a [expr.type]p3. It converts both expressions to this type and returns |
| 8836 | /// it. It does not emit diagnostics (FIXME: that's not true if \p |
| 8837 | /// ConvertArgs is \c true). |
| 8838 | /// |
| 8839 | /// \param Loc The location of the operator requiring these two expressions to |
| 8840 | /// be converted to the composite pointer type. |
| 8841 | /// |
| 8842 | /// \param ConvertArgs If \c false, do not convert E1 and E2 to the target |
| 8843 | /// type. |
| 8844 | QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, |
| 8845 | bool ConvertArgs = true); |
| 8846 | QualType FindCompositePointerType(SourceLocation Loc, ExprResult &E1, |
| 8847 | ExprResult &E2, bool ConvertArgs = true) { |
| 8848 | Expr *E1Tmp = E1.get(), *E2Tmp = E2.get(); |
| 8849 | QualType Composite = |
| 8850 | FindCompositePointerType(Loc, E1&: E1Tmp, E2&: E2Tmp, ConvertArgs); |
| 8851 | E1 = E1Tmp; |
| 8852 | E2 = E2Tmp; |
| 8853 | return Composite; |
| 8854 | } |
| 8855 | |
| 8856 | /// MaybeBindToTemporary - If the passed in expression has a record type with |
| 8857 | /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise |
| 8858 | /// it simply returns the passed in expression. |
| 8859 | ExprResult MaybeBindToTemporary(Expr *E); |
| 8860 | |
| 8861 | /// IgnoredValueConversions - Given that an expression's result is |
| 8862 | /// syntactically ignored, perform any conversions that are |
| 8863 | /// required. |
| 8864 | ExprResult IgnoredValueConversions(Expr *E); |
| 8865 | |
| 8866 | ExprResult CheckUnevaluatedOperand(Expr *E); |
| 8867 | |
| 8868 | IfExistsResult |
| 8869 | CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, |
| 8870 | const DeclarationNameInfo &TargetNameInfo); |
| 8871 | |
| 8872 | IfExistsResult CheckMicrosoftIfExistsSymbol(Scope *S, |
| 8873 | SourceLocation KeywordLoc, |
| 8874 | bool IsIfExists, CXXScopeSpec &SS, |
| 8875 | UnqualifiedId &Name); |
| 8876 | |
| 8877 | RequiresExprBodyDecl * |
| 8878 | ActOnStartRequiresExpr(SourceLocation RequiresKWLoc, |
| 8879 | ArrayRef<ParmVarDecl *> LocalParameters, |
| 8880 | Scope *BodyScope); |
| 8881 | void ActOnFinishRequiresExpr(); |
| 8882 | concepts::Requirement *ActOnSimpleRequirement(Expr *E); |
| 8883 | concepts::Requirement *ActOnTypeRequirement(SourceLocation TypenameKWLoc, |
| 8884 | CXXScopeSpec &SS, |
| 8885 | SourceLocation NameLoc, |
| 8886 | const IdentifierInfo *TypeName, |
| 8887 | TemplateIdAnnotation *TemplateId); |
| 8888 | concepts::Requirement *ActOnCompoundRequirement(Expr *E, |
| 8889 | SourceLocation NoexceptLoc); |
| 8890 | concepts::Requirement *ActOnCompoundRequirement( |
| 8891 | Expr *E, SourceLocation NoexceptLoc, CXXScopeSpec &SS, |
| 8892 | TemplateIdAnnotation *TypeConstraint, unsigned Depth); |
| 8893 | concepts::Requirement *ActOnNestedRequirement(Expr *Constraint); |
| 8894 | concepts::ExprRequirement *BuildExprRequirement( |
| 8895 | Expr *E, bool IsSatisfied, SourceLocation NoexceptLoc, |
| 8896 | concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement); |
| 8897 | concepts::ExprRequirement *BuildExprRequirement( |
| 8898 | concepts::Requirement::SubstitutionDiagnostic *ExprSubstDiag, |
| 8899 | bool IsSatisfied, SourceLocation NoexceptLoc, |
| 8900 | concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement); |
| 8901 | concepts::TypeRequirement *BuildTypeRequirement(TypeSourceInfo *Type); |
| 8902 | concepts::TypeRequirement *BuildTypeRequirement( |
| 8903 | concepts::Requirement::SubstitutionDiagnostic *SubstDiag); |
| 8904 | concepts::NestedRequirement *BuildNestedRequirement(Expr *E); |
| 8905 | concepts::NestedRequirement * |
| 8906 | BuildNestedRequirement(StringRef InvalidConstraintEntity, |
| 8907 | const ASTConstraintSatisfaction &Satisfaction); |
| 8908 | ExprResult ActOnRequiresExpr(SourceLocation RequiresKWLoc, |
| 8909 | RequiresExprBodyDecl *Body, |
| 8910 | SourceLocation LParenLoc, |
| 8911 | ArrayRef<ParmVarDecl *> LocalParameters, |
| 8912 | SourceLocation RParenLoc, |
| 8913 | ArrayRef<concepts::Requirement *> Requirements, |
| 8914 | SourceLocation ClosingBraceLoc); |
| 8915 | |
| 8916 | private: |
| 8917 | ExprResult BuiltinOperatorNewDeleteOverloaded(ExprResult TheCallResult, |
| 8918 | bool IsDelete); |
| 8919 | |
| 8920 | void AnalyzeDeleteExprMismatch(const CXXDeleteExpr *DE); |
| 8921 | void AnalyzeDeleteExprMismatch(FieldDecl *Field, SourceLocation DeleteLoc, |
| 8922 | bool DeleteWasArrayForm); |
| 8923 | |
| 8924 | ///@} |
| 8925 | |
| 8926 | // |
| 8927 | // |
| 8928 | // ------------------------------------------------------------------------- |
| 8929 | // |
| 8930 | // |
| 8931 | |
| 8932 | /// \name Member Access Expressions |
| 8933 | /// Implementations are in SemaExprMember.cpp |
| 8934 | ///@{ |
| 8935 | |
| 8936 | public: |
| 8937 | /// Check whether an expression might be an implicit class member access. |
| 8938 | bool isPotentialImplicitMemberAccess(const CXXScopeSpec &SS, LookupResult &R, |
| 8939 | bool IsAddressOfOperand); |
| 8940 | |
| 8941 | /// Builds an expression which might be an implicit member expression. |
| 8942 | ExprResult BuildPossibleImplicitMemberExpr( |
| 8943 | const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, |
| 8944 | const TemplateArgumentListInfo *TemplateArgs, const Scope *S); |
| 8945 | |
| 8946 | /// Builds an implicit member access expression. The current context |
| 8947 | /// is known to be an instance method, and the given unqualified lookup |
| 8948 | /// set is known to contain only instance members, at least one of which |
| 8949 | /// is from an appropriate type. |
| 8950 | ExprResult |
| 8951 | BuildImplicitMemberExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
| 8952 | LookupResult &R, |
| 8953 | const TemplateArgumentListInfo *TemplateArgs, |
| 8954 | bool IsDefiniteInstance, const Scope *S); |
| 8955 | |
| 8956 | ExprResult ActOnDependentMemberExpr( |
| 8957 | Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OpLoc, |
| 8958 | const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
| 8959 | NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, |
| 8960 | const TemplateArgumentListInfo *TemplateArgs); |
| 8961 | |
| 8962 | /// The main callback when the parser finds something like |
| 8963 | /// expression . [nested-name-specifier] identifier |
| 8964 | /// expression -> [nested-name-specifier] identifier |
| 8965 | /// where 'identifier' encompasses a fairly broad spectrum of |
| 8966 | /// possibilities, including destructor and operator references. |
| 8967 | /// |
| 8968 | /// \param OpKind either tok::arrow or tok::period |
| 8969 | /// \param ObjCImpDecl the current Objective-C \@implementation |
| 8970 | /// decl; this is an ugly hack around the fact that Objective-C |
| 8971 | /// \@implementations aren't properly put in the context chain |
| 8972 | ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, SourceLocation OpLoc, |
| 8973 | tok::TokenKind OpKind, CXXScopeSpec &SS, |
| 8974 | SourceLocation TemplateKWLoc, |
| 8975 | UnqualifiedId &Member, Decl *ObjCImpDecl); |
| 8976 | |
| 8977 | MemberExpr * |
| 8978 | BuildMemberExpr(Expr *Base, bool IsArrow, SourceLocation OpLoc, |
| 8979 | NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, |
| 8980 | ValueDecl *Member, DeclAccessPair FoundDecl, |
| 8981 | bool HadMultipleCandidates, |
| 8982 | const DeclarationNameInfo &MemberNameInfo, QualType Ty, |
| 8983 | ExprValueKind VK, ExprObjectKind OK, |
| 8984 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
| 8985 | |
| 8986 | // Check whether the declarations we found through a nested-name |
| 8987 | // specifier in a member expression are actually members of the base |
| 8988 | // type. The restriction here is: |
| 8989 | // |
| 8990 | // C++ [expr.ref]p2: |
| 8991 | // ... In these cases, the id-expression shall name a |
| 8992 | // member of the class or of one of its base classes. |
| 8993 | // |
| 8994 | // So it's perfectly legitimate for the nested-name specifier to name |
| 8995 | // an unrelated class, and for us to find an overload set including |
| 8996 | // decls from classes which are not superclasses, as long as the decl |
| 8997 | // we actually pick through overload resolution is from a superclass. |
| 8998 | bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, |
| 8999 | const CXXScopeSpec &SS, |
| 9000 | const LookupResult &R); |
| 9001 | |
| 9002 | // This struct is for use by ActOnMemberAccess to allow |
| 9003 | // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after |
| 9004 | // changing the access operator from a '.' to a '->' (to see if that is the |
| 9005 | // change needed to fix an error about an unknown member, e.g. when the class |
| 9006 | // defines a custom operator->). |
| 9007 | struct { |
| 9008 | Scope *; |
| 9009 | UnqualifiedId &; |
| 9010 | Decl *; |
| 9011 | }; |
| 9012 | |
| 9013 | ExprResult BuildMemberReferenceExpr( |
| 9014 | Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow, |
| 9015 | CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
| 9016 | NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, |
| 9017 | const TemplateArgumentListInfo *TemplateArgs, const Scope *S, |
| 9018 | ActOnMemberAccessExtraArgs * = nullptr); |
| 9019 | |
| 9020 | ExprResult |
| 9021 | BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc, |
| 9022 | bool IsArrow, const CXXScopeSpec &SS, |
| 9023 | SourceLocation TemplateKWLoc, |
| 9024 | NamedDecl *FirstQualifierInScope, LookupResult &R, |
| 9025 | const TemplateArgumentListInfo *TemplateArgs, |
| 9026 | const Scope *S, bool SuppressQualifierCheck = false, |
| 9027 | ActOnMemberAccessExtraArgs * = nullptr); |
| 9028 | |
| 9029 | ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, |
| 9030 | SourceLocation OpLoc, |
| 9031 | const CXXScopeSpec &SS, FieldDecl *Field, |
| 9032 | DeclAccessPair FoundDecl, |
| 9033 | const DeclarationNameInfo &MemberNameInfo); |
| 9034 | |
| 9035 | /// Perform conversions on the LHS of a member access expression. |
| 9036 | ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow); |
| 9037 | |
| 9038 | ExprResult BuildAnonymousStructUnionMemberReference( |
| 9039 | const CXXScopeSpec &SS, SourceLocation nameLoc, |
| 9040 | IndirectFieldDecl *indirectField, |
| 9041 | DeclAccessPair FoundDecl = DeclAccessPair::make(D: nullptr, AS: AS_none), |
| 9042 | Expr *baseObjectExpr = nullptr, SourceLocation opLoc = SourceLocation()); |
| 9043 | |
| 9044 | private: |
| 9045 | void CheckMemberAccessOfNoDeref(const MemberExpr *E); |
| 9046 | |
| 9047 | ///@} |
| 9048 | |
| 9049 | // |
| 9050 | // |
| 9051 | // ------------------------------------------------------------------------- |
| 9052 | // |
| 9053 | // |
| 9054 | |
| 9055 | /// \name Initializers |
| 9056 | /// Implementations are in SemaInit.cpp |
| 9057 | ///@{ |
| 9058 | |
| 9059 | public: |
| 9060 | /// Stack of types that correspond to the parameter entities that are |
| 9061 | /// currently being copy-initialized. Can be empty. |
| 9062 | llvm::SmallVector<QualType, 4> CurrentParameterCopyTypes; |
| 9063 | |
| 9064 | llvm::DenseMap<unsigned, CXXDeductionGuideDecl *> |
| 9065 | AggregateDeductionCandidates; |
| 9066 | |
| 9067 | bool IsStringInit(Expr *Init, const ArrayType *AT); |
| 9068 | |
| 9069 | /// Determine whether we can perform aggregate initialization for the purposes |
| 9070 | /// of overload resolution. |
| 9071 | bool CanPerformAggregateInitializationForOverloadResolution( |
| 9072 | const InitializedEntity &Entity, InitListExpr *From); |
| 9073 | |
| 9074 | ExprResult ActOnDesignatedInitializer(Designation &Desig, |
| 9075 | SourceLocation EqualOrColonLoc, |
| 9076 | bool GNUSyntax, ExprResult Init); |
| 9077 | |
| 9078 | /// Check that the lifetime of the initializer (and its subobjects) is |
| 9079 | /// sufficient for initializing the entity, and perform lifetime extension |
| 9080 | /// (when permitted) if not. |
| 9081 | void checkInitializerLifetime(const InitializedEntity &Entity, Expr *Init); |
| 9082 | |
| 9083 | MaterializeTemporaryExpr * |
| 9084 | CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary, |
| 9085 | bool BoundToLvalueReference); |
| 9086 | |
| 9087 | /// If \p E is a prvalue denoting an unmaterialized temporary, materialize |
| 9088 | /// it as an xvalue. In C++98, the result will still be a prvalue, because |
| 9089 | /// we don't have xvalues there. |
| 9090 | ExprResult TemporaryMaterializationConversion(Expr *E); |
| 9091 | |
| 9092 | ExprResult PerformQualificationConversion( |
| 9093 | Expr *E, QualType Ty, ExprValueKind VK = VK_PRValue, |
| 9094 | CheckedConversionKind CCK = CheckedConversionKind::Implicit); |
| 9095 | |
| 9096 | bool CanPerformCopyInitialization(const InitializedEntity &Entity, |
| 9097 | ExprResult Init); |
| 9098 | ExprResult PerformCopyInitialization(const InitializedEntity &Entity, |
| 9099 | SourceLocation EqualLoc, ExprResult Init, |
| 9100 | bool TopLevelOfInitList = false, |
| 9101 | bool AllowExplicit = false); |
| 9102 | |
| 9103 | QualType DeduceTemplateSpecializationFromInitializer( |
| 9104 | TypeSourceInfo *TInfo, const InitializedEntity &Entity, |
| 9105 | const InitializationKind &Kind, MultiExprArg Init); |
| 9106 | |
| 9107 | ///@} |
| 9108 | |
| 9109 | // |
| 9110 | // |
| 9111 | // ------------------------------------------------------------------------- |
| 9112 | // |
| 9113 | // |
| 9114 | |
| 9115 | /// \name C++ Lambda Expressions |
| 9116 | /// Implementations are in SemaLambda.cpp |
| 9117 | ///@{ |
| 9118 | |
| 9119 | public: |
| 9120 | /// Create a new lambda closure type. |
| 9121 | CXXRecordDecl *createLambdaClosureType(SourceRange IntroducerRange, |
| 9122 | TypeSourceInfo *Info, |
| 9123 | unsigned LambdaDependencyKind, |
| 9124 | LambdaCaptureDefault CaptureDefault); |
| 9125 | |
| 9126 | /// Number lambda for linkage purposes if necessary. |
| 9127 | void handleLambdaNumbering(CXXRecordDecl *Class, CXXMethodDecl *Method, |
| 9128 | std::optional<CXXRecordDecl::LambdaNumbering> |
| 9129 | NumberingOverride = std::nullopt); |
| 9130 | |
| 9131 | /// Endow the lambda scope info with the relevant properties. |
| 9132 | void buildLambdaScope(sema::LambdaScopeInfo *LSI, CXXMethodDecl *CallOperator, |
| 9133 | SourceRange IntroducerRange, |
| 9134 | LambdaCaptureDefault CaptureDefault, |
| 9135 | SourceLocation CaptureDefaultLoc, bool ExplicitParams, |
| 9136 | bool Mutable); |
| 9137 | |
| 9138 | CXXMethodDecl *CreateLambdaCallOperator(SourceRange IntroducerRange, |
| 9139 | CXXRecordDecl *Class); |
| 9140 | |
| 9141 | void AddTemplateParametersToLambdaCallOperator( |
| 9142 | CXXMethodDecl *CallOperator, CXXRecordDecl *Class, |
| 9143 | TemplateParameterList *TemplateParams); |
| 9144 | |
| 9145 | void |
| 9146 | CompleteLambdaCallOperator(CXXMethodDecl *Method, SourceLocation LambdaLoc, |
| 9147 | SourceLocation CallOperatorLoc, |
| 9148 | const AssociatedConstraint &TrailingRequiresClause, |
| 9149 | TypeSourceInfo *MethodTyInfo, |
| 9150 | ConstexprSpecKind ConstexprKind, StorageClass SC, |
| 9151 | ArrayRef<ParmVarDecl *> Params, |
| 9152 | bool HasExplicitResultType); |
| 9153 | |
| 9154 | /// Returns true if the explicit object parameter was invalid. |
| 9155 | bool DiagnoseInvalidExplicitObjectParameterInLambda(CXXMethodDecl *Method, |
| 9156 | SourceLocation CallLoc); |
| 9157 | |
| 9158 | /// Perform initialization analysis of the init-capture and perform |
| 9159 | /// any implicit conversions such as an lvalue-to-rvalue conversion if |
| 9160 | /// not being used to initialize a reference. |
| 9161 | ParsedType actOnLambdaInitCaptureInitialization( |
| 9162 | SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, |
| 9163 | IdentifierInfo *Id, LambdaCaptureInitKind InitKind, Expr *&Init) { |
| 9164 | return ParsedType::make(P: buildLambdaInitCaptureInitialization( |
| 9165 | Loc, ByRef, EllipsisLoc, NumExpansions: std::nullopt, Id, |
| 9166 | DirectInit: InitKind != LambdaCaptureInitKind::CopyInit, Init)); |
| 9167 | } |
| 9168 | QualType buildLambdaInitCaptureInitialization(SourceLocation Loc, bool ByRef, |
| 9169 | SourceLocation EllipsisLoc, |
| 9170 | UnsignedOrNone NumExpansions, |
| 9171 | IdentifierInfo *Id, |
| 9172 | bool DirectInit, Expr *&Init); |
| 9173 | |
| 9174 | /// Create a dummy variable within the declcontext of the lambda's |
| 9175 | /// call operator, for name lookup purposes for a lambda init capture. |
| 9176 | /// |
| 9177 | /// CodeGen handles emission of lambda captures, ignoring these dummy |
| 9178 | /// variables appropriately. |
| 9179 | VarDecl *createLambdaInitCaptureVarDecl( |
| 9180 | SourceLocation Loc, QualType InitCaptureType, SourceLocation EllipsisLoc, |
| 9181 | IdentifierInfo *Id, unsigned InitStyle, Expr *Init, DeclContext *DeclCtx); |
| 9182 | |
| 9183 | /// Add an init-capture to a lambda scope. |
| 9184 | void addInitCapture(sema::LambdaScopeInfo *LSI, VarDecl *Var, bool ByRef); |
| 9185 | |
| 9186 | /// Note that we have finished the explicit captures for the |
| 9187 | /// given lambda. |
| 9188 | void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI); |
| 9189 | |
| 9190 | /// Deduce a block or lambda's return type based on the return |
| 9191 | /// statements present in the body. |
| 9192 | void deduceClosureReturnType(sema::CapturingScopeInfo &CSI); |
| 9193 | |
| 9194 | /// Once the Lambdas capture are known, we can start to create the closure, |
| 9195 | /// call operator method, and keep track of the captures. |
| 9196 | /// We do the capture lookup here, but they are not actually captured until |
| 9197 | /// after we know what the qualifiers of the call operator are. |
| 9198 | void ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro, |
| 9199 | Scope *CurContext); |
| 9200 | |
| 9201 | /// This is called after parsing the explicit template parameter list |
| 9202 | /// on a lambda (if it exists) in C++2a. |
| 9203 | void ActOnLambdaExplicitTemplateParameterList(LambdaIntroducer &Intro, |
| 9204 | SourceLocation LAngleLoc, |
| 9205 | ArrayRef<NamedDecl *> TParams, |
| 9206 | SourceLocation RAngleLoc, |
| 9207 | ExprResult RequiresClause); |
| 9208 | |
| 9209 | void ActOnLambdaClosureQualifiers(LambdaIntroducer &Intro, |
| 9210 | SourceLocation MutableLoc); |
| 9211 | |
| 9212 | void ActOnLambdaClosureParameters( |
| 9213 | Scope *LambdaScope, |
| 9214 | MutableArrayRef<DeclaratorChunk::ParamInfo> ParamInfo); |
| 9215 | |
| 9216 | /// ActOnStartOfLambdaDefinition - This is called just before we start |
| 9217 | /// parsing the body of a lambda; it analyzes the explicit captures and |
| 9218 | /// arguments, and sets up various data-structures for the body of the |
| 9219 | /// lambda. |
| 9220 | void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, |
| 9221 | Declarator &ParamInfo, const DeclSpec &DS); |
| 9222 | |
| 9223 | /// ActOnLambdaError - If there is an error parsing a lambda, this callback |
| 9224 | /// is invoked to pop the information about the lambda. |
| 9225 | void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, |
| 9226 | bool IsInstantiation = false); |
| 9227 | |
| 9228 | /// ActOnLambdaExpr - This is called when the body of a lambda expression |
| 9229 | /// was successfully completed. |
| 9230 | ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body); |
| 9231 | |
| 9232 | /// Does copying/destroying the captured variable have side effects? |
| 9233 | bool CaptureHasSideEffects(const sema::Capture &From); |
| 9234 | |
| 9235 | /// Diagnose if an explicit lambda capture is unused. Returns true if a |
| 9236 | /// diagnostic is emitted. |
| 9237 | bool DiagnoseUnusedLambdaCapture(SourceRange CaptureRange, |
| 9238 | SourceRange FixItRange, |
| 9239 | const sema::Capture &From); |
| 9240 | |
| 9241 | /// Build a FieldDecl suitable to hold the given capture. |
| 9242 | FieldDecl *BuildCaptureField(RecordDecl *RD, const sema::Capture &Capture); |
| 9243 | |
| 9244 | /// Initialize the given capture with a suitable expression. |
| 9245 | ExprResult BuildCaptureInit(const sema::Capture &Capture, |
| 9246 | SourceLocation ImplicitCaptureLoc, |
| 9247 | bool IsOpenMPMapping = false); |
| 9248 | |
| 9249 | /// Complete a lambda-expression having processed and attached the |
| 9250 | /// lambda body. |
| 9251 | ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc); |
| 9252 | |
| 9253 | /// Get the return type to use for a lambda's conversion function(s) to |
| 9254 | /// function pointer type, given the type of the call operator. |
| 9255 | QualType |
| 9256 | getLambdaConversionFunctionResultType(const FunctionProtoType *CallOpType, |
| 9257 | CallingConv CC); |
| 9258 | |
| 9259 | ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, |
| 9260 | SourceLocation ConvLocation, |
| 9261 | CXXConversionDecl *Conv, Expr *Src); |
| 9262 | |
| 9263 | class LambdaScopeForCallOperatorInstantiationRAII |
| 9264 | : private FunctionScopeRAII { |
| 9265 | public: |
| 9266 | LambdaScopeForCallOperatorInstantiationRAII( |
| 9267 | Sema &SemasRef, FunctionDecl *FD, MultiLevelTemplateArgumentList MLTAL, |
| 9268 | LocalInstantiationScope &Scope, |
| 9269 | bool ShouldAddDeclsFromParentScope = true); |
| 9270 | }; |
| 9271 | |
| 9272 | /// Compute the mangling number context for a lambda expression or |
| 9273 | /// block literal. Also return the extra mangling decl if any. |
| 9274 | /// |
| 9275 | /// \param DC - The DeclContext containing the lambda expression or |
| 9276 | /// block literal. |
| 9277 | std::tuple<MangleNumberingContext *, Decl *> |
| 9278 | getCurrentMangleNumberContext(const DeclContext *DC); |
| 9279 | |
| 9280 | ///@} |
| 9281 | |
| 9282 | // |
| 9283 | // |
| 9284 | // ------------------------------------------------------------------------- |
| 9285 | // |
| 9286 | // |
| 9287 | |
| 9288 | /// \name Name Lookup |
| 9289 | /// |
| 9290 | /// These routines provide name lookup that is used during semantic |
| 9291 | /// analysis to resolve the various kinds of names (identifiers, |
| 9292 | /// overloaded operator names, constructor names, etc.) into zero or |
| 9293 | /// more declarations within a particular scope. The major entry |
| 9294 | /// points are LookupName, which performs unqualified name lookup, |
| 9295 | /// and LookupQualifiedName, which performs qualified name lookup. |
| 9296 | /// |
| 9297 | /// All name lookup is performed based on some specific criteria, |
| 9298 | /// which specify what names will be visible to name lookup and how |
| 9299 | /// far name lookup should work. These criteria are important both |
| 9300 | /// for capturing language semantics (certain lookups will ignore |
| 9301 | /// certain names, for example) and for performance, since name |
| 9302 | /// lookup is often a bottleneck in the compilation of C++. Name |
| 9303 | /// lookup criteria is specified via the LookupCriteria enumeration. |
| 9304 | /// |
| 9305 | /// The results of name lookup can vary based on the kind of name |
| 9306 | /// lookup performed, the current language, and the translation |
| 9307 | /// unit. In C, for example, name lookup will either return nothing |
| 9308 | /// (no entity found) or a single declaration. In C++, name lookup |
| 9309 | /// can additionally refer to a set of overloaded functions or |
| 9310 | /// result in an ambiguity. All of the possible results of name |
| 9311 | /// lookup are captured by the LookupResult class, which provides |
| 9312 | /// the ability to distinguish among them. |
| 9313 | /// |
| 9314 | /// Implementations are in SemaLookup.cpp |
| 9315 | ///@{ |
| 9316 | |
| 9317 | public: |
| 9318 | /// Tracks whether we are in a context where typo correction is |
| 9319 | /// disabled. |
| 9320 | bool DisableTypoCorrection; |
| 9321 | |
| 9322 | /// The number of typos corrected by CorrectTypo. |
| 9323 | unsigned TyposCorrected; |
| 9324 | |
| 9325 | typedef llvm::SmallSet<SourceLocation, 2> SrcLocSet; |
| 9326 | typedef llvm::DenseMap<IdentifierInfo *, SrcLocSet> IdentifierSourceLocations; |
| 9327 | |
| 9328 | /// A cache containing identifiers for which typo correction failed and |
| 9329 | /// their locations, so that repeated attempts to correct an identifier in a |
| 9330 | /// given location are ignored if typo correction already failed for it. |
| 9331 | IdentifierSourceLocations TypoCorrectionFailures; |
| 9332 | |
| 9333 | /// SpecialMemberOverloadResult - The overloading result for a special member |
| 9334 | /// function. |
| 9335 | /// |
| 9336 | /// This is basically a wrapper around PointerIntPair. The lowest bits of the |
| 9337 | /// integer are used to determine whether overload resolution succeeded. |
| 9338 | class SpecialMemberOverloadResult { |
| 9339 | public: |
| 9340 | enum Kind { NoMemberOrDeleted, Ambiguous, Success }; |
| 9341 | |
| 9342 | private: |
| 9343 | llvm::PointerIntPair<CXXMethodDecl *, 2> Pair; |
| 9344 | |
| 9345 | public: |
| 9346 | SpecialMemberOverloadResult() {} |
| 9347 | SpecialMemberOverloadResult(CXXMethodDecl *MD) |
| 9348 | : Pair(MD, MD->isDeleted() ? NoMemberOrDeleted : Success) {} |
| 9349 | |
| 9350 | CXXMethodDecl *getMethod() const { return Pair.getPointer(); } |
| 9351 | void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); } |
| 9352 | |
| 9353 | Kind getKind() const { return static_cast<Kind>(Pair.getInt()); } |
| 9354 | void setKind(Kind K) { Pair.setInt(K); } |
| 9355 | }; |
| 9356 | |
| 9357 | class SpecialMemberOverloadResultEntry : public llvm::FastFoldingSetNode, |
| 9358 | public SpecialMemberOverloadResult { |
| 9359 | public: |
| 9360 | SpecialMemberOverloadResultEntry(const llvm::FoldingSetNodeID &ID) |
| 9361 | : FastFoldingSetNode(ID) {} |
| 9362 | }; |
| 9363 | |
| 9364 | /// A cache of special member function overload resolution results |
| 9365 | /// for C++ records. |
| 9366 | llvm::FoldingSet<SpecialMemberOverloadResultEntry> SpecialMemberCache; |
| 9367 | |
| 9368 | enum class AcceptableKind { Visible, Reachable }; |
| 9369 | |
| 9370 | // Members have to be NamespaceDecl* or TranslationUnitDecl*. |
| 9371 | // TODO: make this is a typesafe union. |
| 9372 | typedef llvm::SmallSetVector<DeclContext *, 16> AssociatedNamespaceSet; |
| 9373 | typedef llvm::SmallSetVector<CXXRecordDecl *, 16> AssociatedClassSet; |
| 9374 | |
| 9375 | /// Describes the kind of name lookup to perform. |
| 9376 | enum LookupNameKind { |
| 9377 | /// Ordinary name lookup, which finds ordinary names (functions, |
| 9378 | /// variables, typedefs, etc.) in C and most kinds of names |
| 9379 | /// (functions, variables, members, types, etc.) in C++. |
| 9380 | LookupOrdinaryName = 0, |
| 9381 | /// Tag name lookup, which finds the names of enums, classes, |
| 9382 | /// structs, and unions. |
| 9383 | LookupTagName, |
| 9384 | /// Label name lookup. |
| 9385 | LookupLabel, |
| 9386 | /// Member name lookup, which finds the names of |
| 9387 | /// class/struct/union members. |
| 9388 | LookupMemberName, |
| 9389 | /// Look up of an operator name (e.g., operator+) for use with |
| 9390 | /// operator overloading. This lookup is similar to ordinary name |
| 9391 | /// lookup, but will ignore any declarations that are class members. |
| 9392 | LookupOperatorName, |
| 9393 | /// Look up a name following ~ in a destructor name. This is an ordinary |
| 9394 | /// lookup, but prefers tags to typedefs. |
| 9395 | LookupDestructorName, |
| 9396 | /// Look up of a name that precedes the '::' scope resolution |
| 9397 | /// operator in C++. This lookup completely ignores operator, object, |
| 9398 | /// function, and enumerator names (C++ [basic.lookup.qual]p1). |
| 9399 | LookupNestedNameSpecifierName, |
| 9400 | /// Look up a namespace name within a C++ using directive or |
| 9401 | /// namespace alias definition, ignoring non-namespace names (C++ |
| 9402 | /// [basic.lookup.udir]p1). |
| 9403 | LookupNamespaceName, |
| 9404 | /// Look up all declarations in a scope with the given name, |
| 9405 | /// including resolved using declarations. This is appropriate |
| 9406 | /// for checking redeclarations for a using declaration. |
| 9407 | LookupUsingDeclName, |
| 9408 | /// Look up an ordinary name that is going to be redeclared as a |
| 9409 | /// name with linkage. This lookup ignores any declarations that |
| 9410 | /// are outside of the current scope unless they have linkage. See |
| 9411 | /// C99 6.2.2p4-5 and C++ [basic.link]p6. |
| 9412 | LookupRedeclarationWithLinkage, |
| 9413 | /// Look up a friend of a local class. This lookup does not look |
| 9414 | /// outside the innermost non-class scope. See C++11 [class.friend]p11. |
| 9415 | LookupLocalFriendName, |
| 9416 | /// Look up the name of an Objective-C protocol. |
| 9417 | LookupObjCProtocolName, |
| 9418 | /// Look up implicit 'self' parameter of an objective-c method. |
| 9419 | LookupObjCImplicitSelfParam, |
| 9420 | /// Look up the name of an OpenMP user-defined reduction operation. |
| 9421 | LookupOMPReductionName, |
| 9422 | /// Look up the name of an OpenMP user-defined mapper. |
| 9423 | LookupOMPMapperName, |
| 9424 | /// Look up any declaration with any name. |
| 9425 | LookupAnyName |
| 9426 | }; |
| 9427 | |
| 9428 | /// The possible outcomes of name lookup for a literal operator. |
| 9429 | enum LiteralOperatorLookupResult { |
| 9430 | /// The lookup resulted in an error. |
| 9431 | LOLR_Error, |
| 9432 | /// The lookup found no match but no diagnostic was issued. |
| 9433 | LOLR_ErrorNoDiagnostic, |
| 9434 | /// The lookup found a single 'cooked' literal operator, which |
| 9435 | /// expects a normal literal to be built and passed to it. |
| 9436 | LOLR_Cooked, |
| 9437 | /// The lookup found a single 'raw' literal operator, which expects |
| 9438 | /// a string literal containing the spelling of the literal token. |
| 9439 | LOLR_Raw, |
| 9440 | /// The lookup found an overload set of literal operator templates, |
| 9441 | /// which expect the characters of the spelling of the literal token to be |
| 9442 | /// passed as a non-type template argument pack. |
| 9443 | LOLR_Template, |
| 9444 | /// The lookup found an overload set of literal operator templates, |
| 9445 | /// which expect the character type and characters of the spelling of the |
| 9446 | /// string literal token to be passed as template arguments. |
| 9447 | LOLR_StringTemplatePack, |
| 9448 | }; |
| 9449 | |
| 9450 | SpecialMemberOverloadResult |
| 9451 | LookupSpecialMember(CXXRecordDecl *D, CXXSpecialMemberKind SM, bool ConstArg, |
| 9452 | bool VolatileArg, bool RValueThis, bool ConstThis, |
| 9453 | bool VolatileThis); |
| 9454 | |
| 9455 | RedeclarationKind forRedeclarationInCurContext() const; |
| 9456 | |
| 9457 | /// Look up a name, looking for a single declaration. Return |
| 9458 | /// null if the results were absent, ambiguous, or overloaded. |
| 9459 | /// |
| 9460 | /// It is preferable to use the elaborated form and explicitly handle |
| 9461 | /// ambiguity and overloaded. |
| 9462 | NamedDecl *LookupSingleName( |
| 9463 | Scope *S, DeclarationName Name, SourceLocation Loc, |
| 9464 | LookupNameKind NameKind, |
| 9465 | RedeclarationKind Redecl = RedeclarationKind::NotForRedeclaration); |
| 9466 | |
| 9467 | /// Lookup a builtin function, when name lookup would otherwise |
| 9468 | /// fail. |
| 9469 | bool LookupBuiltin(LookupResult &R); |
| 9470 | void LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID); |
| 9471 | |
| 9472 | /// Perform unqualified name lookup starting from a given |
| 9473 | /// scope. |
| 9474 | /// |
| 9475 | /// Unqualified name lookup (C++ [basic.lookup.unqual], C99 6.2.1) is |
| 9476 | /// used to find names within the current scope. For example, 'x' in |
| 9477 | /// @code |
| 9478 | /// int x; |
| 9479 | /// int f() { |
| 9480 | /// return x; // unqualified name look finds 'x' in the global scope |
| 9481 | /// } |
| 9482 | /// @endcode |
| 9483 | /// |
| 9484 | /// Different lookup criteria can find different names. For example, a |
| 9485 | /// particular scope can have both a struct and a function of the same |
| 9486 | /// name, and each can be found by certain lookup criteria. For more |
| 9487 | /// information about lookup criteria, see the documentation for the |
| 9488 | /// class LookupCriteria. |
| 9489 | /// |
| 9490 | /// @param S The scope from which unqualified name lookup will |
| 9491 | /// begin. If the lookup criteria permits, name lookup may also search |
| 9492 | /// in the parent scopes. |
| 9493 | /// |
| 9494 | /// @param [in,out] R Specifies the lookup to perform (e.g., the name to |
| 9495 | /// look up and the lookup kind), and is updated with the results of lookup |
| 9496 | /// including zero or more declarations and possibly additional information |
| 9497 | /// used to diagnose ambiguities. |
| 9498 | /// |
| 9499 | /// @returns \c true if lookup succeeded and false otherwise. |
| 9500 | bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation = false, |
| 9501 | bool ForceNoCPlusPlus = false); |
| 9502 | |
| 9503 | /// Perform qualified name lookup into a given context. |
| 9504 | /// |
| 9505 | /// Qualified name lookup (C++ [basic.lookup.qual]) is used to find |
| 9506 | /// names when the context of those names is explicit specified, e.g., |
| 9507 | /// "std::vector" or "x->member", or as part of unqualified name lookup. |
| 9508 | /// |
| 9509 | /// Different lookup criteria can find different names. For example, a |
| 9510 | /// particular scope can have both a struct and a function of the same |
| 9511 | /// name, and each can be found by certain lookup criteria. For more |
| 9512 | /// information about lookup criteria, see the documentation for the |
| 9513 | /// class LookupCriteria. |
| 9514 | /// |
| 9515 | /// \param R captures both the lookup criteria and any lookup results found. |
| 9516 | /// |
| 9517 | /// \param LookupCtx The context in which qualified name lookup will |
| 9518 | /// search. If the lookup criteria permits, name lookup may also search |
| 9519 | /// in the parent contexts or (for C++ classes) base classes. |
| 9520 | /// |
| 9521 | /// \param InUnqualifiedLookup true if this is qualified name lookup that |
| 9522 | /// occurs as part of unqualified name lookup. |
| 9523 | /// |
| 9524 | /// \returns true if lookup succeeded, false if it failed. |
| 9525 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
| 9526 | bool InUnqualifiedLookup = false); |
| 9527 | |
| 9528 | /// Performs qualified name lookup or special type of lookup for |
| 9529 | /// "__super::" scope specifier. |
| 9530 | /// |
| 9531 | /// This routine is a convenience overload meant to be called from contexts |
| 9532 | /// that need to perform a qualified name lookup with an optional C++ scope |
| 9533 | /// specifier that might require special kind of lookup. |
| 9534 | /// |
| 9535 | /// \param R captures both the lookup criteria and any lookup results found. |
| 9536 | /// |
| 9537 | /// \param LookupCtx The context in which qualified name lookup will |
| 9538 | /// search. |
| 9539 | /// |
| 9540 | /// \param SS An optional C++ scope-specifier. |
| 9541 | /// |
| 9542 | /// \returns true if lookup succeeded, false if it failed. |
| 9543 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
| 9544 | CXXScopeSpec &SS); |
| 9545 | |
| 9546 | /// Performs name lookup for a name that was parsed in the |
| 9547 | /// source code, and may contain a C++ scope specifier. |
| 9548 | /// |
| 9549 | /// This routine is a convenience routine meant to be called from |
| 9550 | /// contexts that receive a name and an optional C++ scope specifier |
| 9551 | /// (e.g., "N::M::x"). It will then perform either qualified or |
| 9552 | /// unqualified name lookup (with LookupQualifiedName or LookupName, |
| 9553 | /// respectively) on the given name and return those results. It will |
| 9554 | /// perform a special type of lookup for "__super::" scope specifier. |
| 9555 | /// |
| 9556 | /// @param S The scope from which unqualified name lookup will |
| 9557 | /// begin. |
| 9558 | /// |
| 9559 | /// @param SS An optional C++ scope-specifier, e.g., "::N::M". |
| 9560 | /// |
| 9561 | /// @param EnteringContext Indicates whether we are going to enter the |
| 9562 | /// context of the scope-specifier SS (if present). |
| 9563 | /// |
| 9564 | /// @returns True if any decls were found (but possibly ambiguous) |
| 9565 | bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, |
| 9566 | QualType ObjectType, bool AllowBuiltinCreation = false, |
| 9567 | bool EnteringContext = false); |
| 9568 | |
| 9569 | /// Perform qualified name lookup into all base classes of the given |
| 9570 | /// class. |
| 9571 | /// |
| 9572 | /// \param R captures both the lookup criteria and any lookup results found. |
| 9573 | /// |
| 9574 | /// \param Class The context in which qualified name lookup will |
| 9575 | /// search. Name lookup will search in all base classes merging the results. |
| 9576 | /// |
| 9577 | /// @returns True if any decls were found (but possibly ambiguous) |
| 9578 | bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class); |
| 9579 | |
| 9580 | void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, |
| 9581 | UnresolvedSetImpl &Functions); |
| 9582 | |
| 9583 | /// LookupOrCreateLabel - Do a name lookup of a label with the specified name. |
| 9584 | /// If GnuLabelLoc is a valid source location, then this is a definition |
| 9585 | /// of an __label__ label name, otherwise it is a normal label definition |
| 9586 | /// or use. |
| 9587 | LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, |
| 9588 | SourceLocation GnuLabelLoc = SourceLocation()); |
| 9589 | |
| 9590 | /// Perform a name lookup for a label with the specified name; this does not |
| 9591 | /// create a new label if the lookup fails. |
| 9592 | LabelDecl *LookupExistingLabel(IdentifierInfo *II, SourceLocation IdentLoc); |
| 9593 | |
| 9594 | /// Look up the constructors for the given class. |
| 9595 | DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class); |
| 9596 | |
| 9597 | /// Look up the default constructor for the given class. |
| 9598 | CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class); |
| 9599 | |
| 9600 | /// Look up the copying constructor for the given class. |
| 9601 | CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class, |
| 9602 | unsigned Quals); |
| 9603 | |
| 9604 | /// Look up the copying assignment operator for the given class. |
| 9605 | CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals, |
| 9606 | bool RValueThis, unsigned ThisQuals); |
| 9607 | |
| 9608 | /// Look up the moving constructor for the given class. |
| 9609 | CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class, |
| 9610 | unsigned Quals); |
| 9611 | |
| 9612 | /// Look up the moving assignment operator for the given class. |
| 9613 | CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals, |
| 9614 | bool RValueThis, unsigned ThisQuals); |
| 9615 | |
| 9616 | /// Look for the destructor of the given class. |
| 9617 | /// |
| 9618 | /// During semantic analysis, this routine should be used in lieu of |
| 9619 | /// CXXRecordDecl::getDestructor(). |
| 9620 | /// |
| 9621 | /// \returns The destructor for this class. |
| 9622 | CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class); |
| 9623 | |
| 9624 | /// Force the declaration of any implicitly-declared members of this |
| 9625 | /// class. |
| 9626 | void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); |
| 9627 | |
| 9628 | /// Make a merged definition of an existing hidden definition \p ND |
| 9629 | /// visible at the specified location. |
| 9630 | void makeMergedDefinitionVisible(NamedDecl *ND); |
| 9631 | |
| 9632 | /// Check ODR hashes for C/ObjC when merging types from modules. |
| 9633 | /// Differently from C++, actually parse the body and reject in case |
| 9634 | /// of a mismatch. |
| 9635 | template <typename T, |
| 9636 | typename = std::enable_if_t<std::is_base_of<NamedDecl, T>::value>> |
| 9637 | bool ActOnDuplicateODRHashDefinition(T *Duplicate, T *Previous) { |
| 9638 | if (Duplicate->getODRHash() != Previous->getODRHash()) |
| 9639 | return false; |
| 9640 | |
| 9641 | // Make the previous decl visible. |
| 9642 | makeMergedDefinitionVisible(ND: Previous); |
| 9643 | return true; |
| 9644 | } |
| 9645 | |
| 9646 | /// Get the set of additional modules that should be checked during |
| 9647 | /// name lookup. A module and its imports become visible when instanting a |
| 9648 | /// template defined within it. |
| 9649 | llvm::DenseSet<Module *> &getLookupModules(); |
| 9650 | |
| 9651 | bool hasVisibleMergedDefinition(const NamedDecl *Def); |
| 9652 | bool hasMergedDefinitionInCurrentModule(const NamedDecl *Def); |
| 9653 | |
| 9654 | /// Determine if the template parameter \p D has a visible default argument. |
| 9655 | bool |
| 9656 | hasVisibleDefaultArgument(const NamedDecl *D, |
| 9657 | llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
| 9658 | /// Determine if the template parameter \p D has a reachable default argument. |
| 9659 | bool hasReachableDefaultArgument( |
| 9660 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
| 9661 | /// Determine if the template parameter \p D has a reachable default argument. |
| 9662 | bool hasAcceptableDefaultArgument(const NamedDecl *D, |
| 9663 | llvm::SmallVectorImpl<Module *> *Modules, |
| 9664 | Sema::AcceptableKind Kind); |
| 9665 | |
| 9666 | /// Determine if there is a visible declaration of \p D that is an explicit |
| 9667 | /// specialization declaration for a specialization of a template. (For a |
| 9668 | /// member specialization, use hasVisibleMemberSpecialization.) |
| 9669 | bool hasVisibleExplicitSpecialization( |
| 9670 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
| 9671 | /// Determine if there is a reachable declaration of \p D that is an explicit |
| 9672 | /// specialization declaration for a specialization of a template. (For a |
| 9673 | /// member specialization, use hasReachableMemberSpecialization.) |
| 9674 | bool hasReachableExplicitSpecialization( |
| 9675 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
| 9676 | |
| 9677 | /// Determine if there is a visible declaration of \p D that is a member |
| 9678 | /// specialization declaration (as opposed to an instantiated declaration). |
| 9679 | bool hasVisibleMemberSpecialization( |
| 9680 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
| 9681 | /// Determine if there is a reachable declaration of \p D that is a member |
| 9682 | /// specialization declaration (as opposed to an instantiated declaration). |
| 9683 | bool hasReachableMemberSpecialization( |
| 9684 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
| 9685 | |
| 9686 | bool isModuleVisible(const Module *M, bool ModulePrivate = false); |
| 9687 | |
| 9688 | /// Determine whether any declaration of an entity is visible. |
| 9689 | bool |
| 9690 | hasVisibleDeclaration(const NamedDecl *D, |
| 9691 | llvm::SmallVectorImpl<Module *> *Modules = nullptr) { |
| 9692 | return isVisible(D) || hasVisibleDeclarationSlow(D, Modules); |
| 9693 | } |
| 9694 | |
| 9695 | bool hasVisibleDeclarationSlow(const NamedDecl *D, |
| 9696 | llvm::SmallVectorImpl<Module *> *Modules); |
| 9697 | /// Determine whether any declaration of an entity is reachable. |
| 9698 | bool |
| 9699 | hasReachableDeclaration(const NamedDecl *D, |
| 9700 | llvm::SmallVectorImpl<Module *> *Modules = nullptr) { |
| 9701 | return isReachable(D) || hasReachableDeclarationSlow(D, Modules); |
| 9702 | } |
| 9703 | bool hasReachableDeclarationSlow( |
| 9704 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
| 9705 | |
| 9706 | void diagnoseTypo(const TypoCorrection &Correction, |
| 9707 | const PartialDiagnostic &TypoDiag, |
| 9708 | bool ErrorRecovery = true); |
| 9709 | |
| 9710 | /// Diagnose a successfully-corrected typo. Separated from the correction |
| 9711 | /// itself to allow external validation of the result, etc. |
| 9712 | /// |
| 9713 | /// \param Correction The result of performing typo correction. |
| 9714 | /// \param TypoDiag The diagnostic to produce. This will have the corrected |
| 9715 | /// string added to it (and usually also a fixit). |
| 9716 | /// \param PrevNote A note to use when indicating the location of the entity |
| 9717 | /// to which we are correcting. Will have the correction string added |
| 9718 | /// to it. |
| 9719 | /// \param ErrorRecovery If \c true (the default), the caller is going to |
| 9720 | /// recover from the typo as if the corrected string had been typed. |
| 9721 | /// In this case, \c PDiag must be an error, and we will attach a fixit |
| 9722 | /// to it. |
| 9723 | void diagnoseTypo(const TypoCorrection &Correction, |
| 9724 | const PartialDiagnostic &TypoDiag, |
| 9725 | const PartialDiagnostic &PrevNote, |
| 9726 | bool ErrorRecovery = true); |
| 9727 | |
| 9728 | /// Find the associated classes and namespaces for |
| 9729 | /// argument-dependent lookup for a call with the given set of |
| 9730 | /// arguments. |
| 9731 | /// |
| 9732 | /// This routine computes the sets of associated classes and associated |
| 9733 | /// namespaces searched by argument-dependent lookup |
| 9734 | /// (C++ [basic.lookup.argdep]) for a given set of arguments. |
| 9735 | void FindAssociatedClassesAndNamespaces( |
| 9736 | SourceLocation InstantiationLoc, ArrayRef<Expr *> Args, |
| 9737 | AssociatedNamespaceSet &AssociatedNamespaces, |
| 9738 | AssociatedClassSet &AssociatedClasses); |
| 9739 | |
| 9740 | /// Produce a diagnostic describing the ambiguity that resulted |
| 9741 | /// from name lookup. |
| 9742 | /// |
| 9743 | /// \param Result The result of the ambiguous lookup to be diagnosed. |
| 9744 | void DiagnoseAmbiguousLookup(LookupResult &Result); |
| 9745 | |
| 9746 | /// LookupLiteralOperator - Determine which literal operator should be used |
| 9747 | /// for a user-defined literal, per C++11 [lex.ext]. |
| 9748 | /// |
| 9749 | /// Normal overload resolution is not used to select which literal operator to |
| 9750 | /// call for a user-defined literal. Look up the provided literal operator |
| 9751 | /// name, and filter the results to the appropriate set for the given argument |
| 9752 | /// types. |
| 9753 | LiteralOperatorLookupResult |
| 9754 | LookupLiteralOperator(Scope *S, LookupResult &R, ArrayRef<QualType> ArgTys, |
| 9755 | bool AllowRaw, bool AllowTemplate, |
| 9756 | bool AllowStringTemplate, bool DiagnoseMissing, |
| 9757 | StringLiteral *StringLit = nullptr); |
| 9758 | |
| 9759 | void ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc, |
| 9760 | ArrayRef<Expr *> Args, ADLResult &Functions); |
| 9761 | |
| 9762 | void LookupVisibleDecls(Scope *S, LookupNameKind Kind, |
| 9763 | VisibleDeclConsumer &Consumer, |
| 9764 | bool IncludeGlobalScope = true, |
| 9765 | bool LoadExternal = true); |
| 9766 | void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind, |
| 9767 | VisibleDeclConsumer &Consumer, |
| 9768 | bool IncludeGlobalScope = true, |
| 9769 | bool IncludeDependentBases = false, |
| 9770 | bool LoadExternal = true); |
| 9771 | |
| 9772 | /// Try to "correct" a typo in the source code by finding |
| 9773 | /// visible declarations whose names are similar to the name that was |
| 9774 | /// present in the source code. |
| 9775 | /// |
| 9776 | /// \param TypoName the \c DeclarationNameInfo structure that contains |
| 9777 | /// the name that was present in the source code along with its location. |
| 9778 | /// |
| 9779 | /// \param LookupKind the name-lookup criteria used to search for the name. |
| 9780 | /// |
| 9781 | /// \param S the scope in which name lookup occurs. |
| 9782 | /// |
| 9783 | /// \param SS the nested-name-specifier that precedes the name we're |
| 9784 | /// looking for, if present. |
| 9785 | /// |
| 9786 | /// \param CCC A CorrectionCandidateCallback object that provides further |
| 9787 | /// validation of typo correction candidates. It also provides flags for |
| 9788 | /// determining the set of keywords permitted. |
| 9789 | /// |
| 9790 | /// \param MemberContext if non-NULL, the context in which to look for |
| 9791 | /// a member access expression. |
| 9792 | /// |
| 9793 | /// \param EnteringContext whether we're entering the context described by |
| 9794 | /// the nested-name-specifier SS. |
| 9795 | /// |
| 9796 | /// \param OPT when non-NULL, the search for visible declarations will |
| 9797 | /// also walk the protocols in the qualified interfaces of \p OPT. |
| 9798 | /// |
| 9799 | /// \returns a \c TypoCorrection containing the corrected name if the typo |
| 9800 | /// along with information such as the \c NamedDecl where the corrected name |
| 9801 | /// was declared, and any additional \c NestedNameSpecifier needed to access |
| 9802 | /// it (C++ only). The \c TypoCorrection is empty if there is no correction. |
| 9803 | TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, |
| 9804 | Sema::LookupNameKind LookupKind, Scope *S, |
| 9805 | CXXScopeSpec *SS, CorrectionCandidateCallback &CCC, |
| 9806 | CorrectTypoKind Mode, |
| 9807 | DeclContext *MemberContext = nullptr, |
| 9808 | bool EnteringContext = false, |
| 9809 | const ObjCObjectPointerType *OPT = nullptr, |
| 9810 | bool RecordFailure = true); |
| 9811 | |
| 9812 | /// Kinds of missing import. Note, the values of these enumerators correspond |
| 9813 | /// to %select values in diagnostics. |
| 9814 | enum class MissingImportKind { |
| 9815 | Declaration, |
| 9816 | Definition, |
| 9817 | DefaultArgument, |
| 9818 | ExplicitSpecialization, |
| 9819 | PartialSpecialization |
| 9820 | }; |
| 9821 | |
| 9822 | /// Diagnose that the specified declaration needs to be visible but |
| 9823 | /// isn't, and suggest a module import that would resolve the problem. |
| 9824 | void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl, |
| 9825 | MissingImportKind MIK, bool Recover = true); |
| 9826 | void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl, |
| 9827 | SourceLocation DeclLoc, ArrayRef<Module *> Modules, |
| 9828 | MissingImportKind MIK, bool Recover); |
| 9829 | |
| 9830 | /// Called on #pragma clang __debug dump II |
| 9831 | void ActOnPragmaDump(Scope *S, SourceLocation Loc, IdentifierInfo *II); |
| 9832 | |
| 9833 | /// Called on #pragma clang __debug dump E |
| 9834 | void ActOnPragmaDump(Expr *E); |
| 9835 | |
| 9836 | private: |
| 9837 | // The set of known/encountered (unique, canonicalized) NamespaceDecls. |
| 9838 | // |
| 9839 | // The boolean value will be true to indicate that the namespace was loaded |
| 9840 | // from an AST/PCH file, or false otherwise. |
| 9841 | llvm::MapVector<NamespaceDecl *, bool> KnownNamespaces; |
| 9842 | |
| 9843 | /// Whether we have already loaded known namespaces from an extenal |
| 9844 | /// source. |
| 9845 | bool LoadedExternalKnownNamespaces; |
| 9846 | |
| 9847 | bool CppLookupName(LookupResult &R, Scope *S); |
| 9848 | |
| 9849 | /// Determine if we could use all the declarations in the module. |
| 9850 | bool isUsableModule(const Module *M); |
| 9851 | |
| 9852 | /// Helper for CorrectTypo used to create and populate a new |
| 9853 | /// TypoCorrectionConsumer. Returns nullptr if typo correction should be |
| 9854 | /// skipped entirely. |
| 9855 | std::unique_ptr<TypoCorrectionConsumer> makeTypoCorrectionConsumer( |
| 9856 | const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, |
| 9857 | Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC, |
| 9858 | DeclContext *MemberContext, bool EnteringContext, |
| 9859 | const ObjCObjectPointerType *OPT, bool ErrorRecovery); |
| 9860 | |
| 9861 | /// Cache for module units which is usable for current module. |
| 9862 | llvm::DenseSet<const Module *> UsableModuleUnitsCache; |
| 9863 | |
| 9864 | /// Record the typo correction failure and return an empty correction. |
| 9865 | TypoCorrection FailedCorrection(IdentifierInfo *Typo, SourceLocation TypoLoc, |
| 9866 | bool RecordFailure = true) { |
| 9867 | if (RecordFailure) |
| 9868 | TypoCorrectionFailures[Typo].insert(V: TypoLoc); |
| 9869 | return TypoCorrection(); |
| 9870 | } |
| 9871 | |
| 9872 | bool isAcceptableSlow(const NamedDecl *D, AcceptableKind Kind); |
| 9873 | |
| 9874 | /// Determine whether two declarations should be linked together, given that |
| 9875 | /// the old declaration might not be visible and the new declaration might |
| 9876 | /// not have external linkage. |
| 9877 | bool shouldLinkPossiblyHiddenDecl(const NamedDecl *Old, |
| 9878 | const NamedDecl *New) { |
| 9879 | if (isVisible(D: Old)) |
| 9880 | return true; |
| 9881 | // See comment in below overload for why it's safe to compute the linkage |
| 9882 | // of the new declaration here. |
| 9883 | if (New->isExternallyDeclarable()) { |
| 9884 | assert(Old->isExternallyDeclarable() && |
| 9885 | "should not have found a non-externally-declarable previous decl" ); |
| 9886 | return true; |
| 9887 | } |
| 9888 | return false; |
| 9889 | } |
| 9890 | bool shouldLinkPossiblyHiddenDecl(LookupResult &Old, const NamedDecl *New); |
| 9891 | |
| 9892 | ///@} |
| 9893 | |
| 9894 | // |
| 9895 | // |
| 9896 | // ------------------------------------------------------------------------- |
| 9897 | // |
| 9898 | // |
| 9899 | |
| 9900 | /// \name Modules |
| 9901 | /// Implementations are in SemaModule.cpp |
| 9902 | ///@{ |
| 9903 | |
| 9904 | public: |
| 9905 | /// Get the module unit whose scope we are currently within. |
| 9906 | Module *getCurrentModule() const { |
| 9907 | return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module; |
| 9908 | } |
| 9909 | |
| 9910 | /// Is the module scope we are an implementation unit? |
| 9911 | bool currentModuleIsImplementation() const { |
| 9912 | return ModuleScopes.empty() |
| 9913 | ? false |
| 9914 | : ModuleScopes.back().Module->isModuleImplementation(); |
| 9915 | } |
| 9916 | |
| 9917 | // When loading a non-modular PCH files, this is used to restore module |
| 9918 | // visibility. |
| 9919 | void makeModuleVisible(Module *Mod, SourceLocation ImportLoc) { |
| 9920 | VisibleModules.setVisible(M: Mod, Loc: ImportLoc); |
| 9921 | } |
| 9922 | |
| 9923 | enum class ModuleDeclKind { |
| 9924 | Interface, ///< 'export module X;' |
| 9925 | Implementation, ///< 'module X;' |
| 9926 | PartitionInterface, ///< 'export module X:Y;' |
| 9927 | PartitionImplementation, ///< 'module X:Y;' |
| 9928 | }; |
| 9929 | |
| 9930 | /// An enumeration to represent the transition of states in parsing module |
| 9931 | /// fragments and imports. If we are not parsing a C++20 TU, or we find |
| 9932 | /// an error in state transition, the state is set to NotACXX20Module. |
| 9933 | enum class ModuleImportState { |
| 9934 | FirstDecl, ///< Parsing the first decl in a TU. |
| 9935 | GlobalFragment, ///< after 'module;' but before 'module X;' |
| 9936 | ImportAllowed, ///< after 'module X;' but before any non-import decl. |
| 9937 | ImportFinished, ///< after any non-import decl. |
| 9938 | PrivateFragmentImportAllowed, ///< after 'module :private;' but before any |
| 9939 | ///< non-import decl. |
| 9940 | PrivateFragmentImportFinished, ///< after 'module :private;' but a |
| 9941 | ///< non-import decl has already been seen. |
| 9942 | NotACXX20Module ///< Not a C++20 TU, or an invalid state was found. |
| 9943 | }; |
| 9944 | |
| 9945 | /// The parser has processed a module-declaration that begins the definition |
| 9946 | /// of a module interface or implementation. |
| 9947 | DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc, |
| 9948 | SourceLocation ModuleLoc, ModuleDeclKind MDK, |
| 9949 | ModuleIdPath Path, ModuleIdPath Partition, |
| 9950 | ModuleImportState &ImportState, |
| 9951 | bool SeenNoTrivialPPDirective); |
| 9952 | |
| 9953 | /// The parser has processed a global-module-fragment declaration that begins |
| 9954 | /// the definition of the global module fragment of the current module unit. |
| 9955 | /// \param ModuleLoc The location of the 'module' keyword. |
| 9956 | DeclGroupPtrTy ActOnGlobalModuleFragmentDecl(SourceLocation ModuleLoc); |
| 9957 | |
| 9958 | /// The parser has processed a private-module-fragment declaration that begins |
| 9959 | /// the definition of the private module fragment of the current module unit. |
| 9960 | /// \param ModuleLoc The location of the 'module' keyword. |
| 9961 | /// \param PrivateLoc The location of the 'private' keyword. |
| 9962 | DeclGroupPtrTy ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc, |
| 9963 | SourceLocation PrivateLoc); |
| 9964 | |
| 9965 | /// The parser has processed a module import declaration. |
| 9966 | /// |
| 9967 | /// \param StartLoc The location of the first token in the declaration. This |
| 9968 | /// could be the location of an '@', 'export', or 'import'. |
| 9969 | /// \param ExportLoc The location of the 'export' keyword, if any. |
| 9970 | /// \param ImportLoc The location of the 'import' keyword. |
| 9971 | /// \param Path The module toplevel name as an access path. |
| 9972 | /// \param IsPartition If the name is for a partition. |
| 9973 | DeclResult ActOnModuleImport(SourceLocation StartLoc, |
| 9974 | SourceLocation ExportLoc, |
| 9975 | SourceLocation ImportLoc, ModuleIdPath Path, |
| 9976 | bool IsPartition = false); |
| 9977 | DeclResult ActOnModuleImport(SourceLocation StartLoc, |
| 9978 | SourceLocation ExportLoc, |
| 9979 | SourceLocation ImportLoc, Module *M, |
| 9980 | ModuleIdPath Path = {}); |
| 9981 | |
| 9982 | /// The parser has processed a module import translated from a |
| 9983 | /// #include or similar preprocessing directive. |
| 9984 | void ActOnAnnotModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
| 9985 | void BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
| 9986 | |
| 9987 | /// The parsed has entered a submodule. |
| 9988 | void ActOnAnnotModuleBegin(SourceLocation DirectiveLoc, Module *Mod); |
| 9989 | /// The parser has left a submodule. |
| 9990 | void ActOnAnnotModuleEnd(SourceLocation DirectiveLoc, Module *Mod); |
| 9991 | |
| 9992 | /// Create an implicit import of the given module at the given |
| 9993 | /// source location, for error recovery, if possible. |
| 9994 | /// |
| 9995 | /// This routine is typically used when an entity found by name lookup |
| 9996 | /// is actually hidden within a module that we know about but the user |
| 9997 | /// has forgotten to import. |
| 9998 | void createImplicitModuleImportForErrorRecovery(SourceLocation Loc, |
| 9999 | Module *Mod); |
| 10000 | |
| 10001 | /// We have parsed the start of an export declaration, including the '{' |
| 10002 | /// (if present). |
| 10003 | Decl *ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc, |
| 10004 | SourceLocation LBraceLoc); |
| 10005 | |
| 10006 | /// Complete the definition of an export declaration. |
| 10007 | Decl *ActOnFinishExportDecl(Scope *S, Decl *ExportDecl, |
| 10008 | SourceLocation RBraceLoc); |
| 10009 | |
| 10010 | private: |
| 10011 | /// The parser has begun a translation unit to be compiled as a C++20 |
| 10012 | /// Header Unit, helper for ActOnStartOfTranslationUnit() only. |
| 10013 | void HandleStartOfHeaderUnit(); |
| 10014 | |
| 10015 | struct ModuleScope { |
| 10016 | SourceLocation BeginLoc; |
| 10017 | clang::Module *Module = nullptr; |
| 10018 | VisibleModuleSet OuterVisibleModules; |
| 10019 | }; |
| 10020 | /// The modules we're currently parsing. |
| 10021 | llvm::SmallVector<ModuleScope, 16> ModuleScopes; |
| 10022 | |
| 10023 | /// For an interface unit, this is the implicitly imported interface unit. |
| 10024 | clang::Module *ThePrimaryInterface = nullptr; |
| 10025 | |
| 10026 | /// The explicit global module fragment of the current translation unit. |
| 10027 | /// The explicit Global Module Fragment, as specified in C++ |
| 10028 | /// [module.global.frag]. |
| 10029 | clang::Module *TheGlobalModuleFragment = nullptr; |
| 10030 | |
| 10031 | /// The implicit global module fragments of the current translation unit. |
| 10032 | /// |
| 10033 | /// The contents in the implicit global module fragment can't be discarded. |
| 10034 | clang::Module *TheImplicitGlobalModuleFragment = nullptr; |
| 10035 | |
| 10036 | /// Namespace definitions that we will export when they finish. |
| 10037 | llvm::SmallPtrSet<const NamespaceDecl *, 8> DeferredExportedNamespaces; |
| 10038 | |
| 10039 | /// In a C++ standard module, inline declarations require a definition to be |
| 10040 | /// present at the end of a definition domain. This set holds the decls to |
| 10041 | /// be checked at the end of the TU. |
| 10042 | llvm::SmallPtrSet<const FunctionDecl *, 8> PendingInlineFuncDecls; |
| 10043 | |
| 10044 | /// Helper function to judge if we are in module purview. |
| 10045 | /// Return false if we are not in a module. |
| 10046 | bool isCurrentModulePurview() const; |
| 10047 | |
| 10048 | /// Enter the scope of the explicit global module fragment. |
| 10049 | Module *PushGlobalModuleFragment(SourceLocation BeginLoc); |
| 10050 | /// Leave the scope of the explicit global module fragment. |
| 10051 | void PopGlobalModuleFragment(); |
| 10052 | |
| 10053 | /// Enter the scope of an implicit global module fragment. |
| 10054 | Module *PushImplicitGlobalModuleFragment(SourceLocation BeginLoc); |
| 10055 | /// Leave the scope of an implicit global module fragment. |
| 10056 | void PopImplicitGlobalModuleFragment(); |
| 10057 | |
| 10058 | VisibleModuleSet VisibleModules; |
| 10059 | |
| 10060 | /// Whether we had imported any named modules. |
| 10061 | bool HadImportedNamedModules = false; |
| 10062 | /// The set of instantiations we need to check if they references TU-local |
| 10063 | /// entity from TUs. This only makes sense if we imported any named modules. |
| 10064 | llvm::SmallVector<std::pair<FunctionDecl *, SourceLocation>> |
| 10065 | PendingCheckReferenceForTULocal; |
| 10066 | /// Implement [basic.link]p18, which requires that we can't use TU-local |
| 10067 | /// entities from other TUs (ignoring header units). |
| 10068 | void checkReferenceToTULocalFromOtherTU(FunctionDecl *FD, |
| 10069 | SourceLocation PointOfInstantiation); |
| 10070 | /// Implement [basic.link]p17, which diagnose for non TU local exposure in |
| 10071 | /// module interface or module partition. |
| 10072 | void checkExposure(const TranslationUnitDecl *TU); |
| 10073 | |
| 10074 | ///@} |
| 10075 | |
| 10076 | // |
| 10077 | // |
| 10078 | // ------------------------------------------------------------------------- |
| 10079 | // |
| 10080 | // |
| 10081 | |
| 10082 | /// \name C++ Overloading |
| 10083 | /// Implementations are in SemaOverload.cpp |
| 10084 | ///@{ |
| 10085 | |
| 10086 | public: |
| 10087 | /// Whether deferrable diagnostics should be deferred. |
| 10088 | bool DeferDiags = false; |
| 10089 | |
| 10090 | /// RAII class to control scope of DeferDiags. |
| 10091 | class DeferDiagsRAII { |
| 10092 | Sema &S; |
| 10093 | bool SavedDeferDiags = false; |
| 10094 | |
| 10095 | public: |
| 10096 | DeferDiagsRAII(Sema &S, bool DeferDiags) |
| 10097 | : S(S), SavedDeferDiags(S.DeferDiags) { |
| 10098 | S.DeferDiags = SavedDeferDiags || DeferDiags; |
| 10099 | } |
| 10100 | ~DeferDiagsRAII() { S.DeferDiags = SavedDeferDiags; } |
| 10101 | DeferDiagsRAII(const DeferDiagsRAII &) = delete; |
| 10102 | DeferDiagsRAII &operator=(const DeferDiagsRAII &) = delete; |
| 10103 | }; |
| 10104 | |
| 10105 | /// Flag indicating if Sema is building a recovery call expression. |
| 10106 | /// |
| 10107 | /// This flag is used to avoid building recovery call expressions |
| 10108 | /// if Sema is already doing so, which would cause infinite recursions. |
| 10109 | bool IsBuildingRecoveryCallExpr; |
| 10110 | |
| 10111 | /// Determine whether the given New declaration is an overload of the |
| 10112 | /// declarations in Old. This routine returns OverloadKind::Match or |
| 10113 | /// OverloadKind::NonFunction if New and Old cannot be overloaded, e.g., if |
| 10114 | /// New has the same signature as some function in Old (C++ 1.3.10) or if the |
| 10115 | /// Old declarations aren't functions (or function templates) at all. When it |
| 10116 | /// does return OverloadKind::Match or OverloadKind::NonFunction, MatchedDecl |
| 10117 | /// will point to the decl that New cannot be overloaded with. This decl may |
| 10118 | /// be a UsingShadowDecl on top of the underlying declaration. |
| 10119 | /// |
| 10120 | /// Example: Given the following input: |
| 10121 | /// |
| 10122 | /// void f(int, float); // #1 |
| 10123 | /// void f(int, int); // #2 |
| 10124 | /// int f(int, int); // #3 |
| 10125 | /// |
| 10126 | /// When we process #1, there is no previous declaration of "f", so IsOverload |
| 10127 | /// will not be used. |
| 10128 | /// |
| 10129 | /// When we process #2, Old contains only the FunctionDecl for #1. By |
| 10130 | /// comparing the parameter types, we see that #1 and #2 are overloaded (since |
| 10131 | /// they have different signatures), so this routine returns |
| 10132 | /// OverloadKind::Overload; MatchedDecl is unchanged. |
| 10133 | /// |
| 10134 | /// When we process #3, Old is an overload set containing #1 and #2. We |
| 10135 | /// compare the signatures of #3 to #1 (they're overloaded, so we do nothing) |
| 10136 | /// and then #3 to #2. Since the signatures of #3 and #2 are identical (return |
| 10137 | /// types of functions are not part of the signature), IsOverload returns |
| 10138 | /// OverloadKind::Match and MatchedDecl will be set to point to the |
| 10139 | /// FunctionDecl for #2. |
| 10140 | /// |
| 10141 | /// 'NewIsUsingShadowDecl' indicates that 'New' is being introduced into a |
| 10142 | /// class by a using declaration. The rules for whether to hide shadow |
| 10143 | /// declarations ignore some properties which otherwise figure into a function |
| 10144 | /// template's signature. |
| 10145 | OverloadKind CheckOverload(Scope *S, FunctionDecl *New, |
| 10146 | const LookupResult &OldDecls, NamedDecl *&OldDecl, |
| 10147 | bool UseMemberUsingDeclRules); |
| 10148 | bool IsOverload(FunctionDecl *New, FunctionDecl *Old, |
| 10149 | bool UseMemberUsingDeclRules, bool ConsiderCudaAttrs = true); |
| 10150 | |
| 10151 | // Checks whether MD constitutes an override the base class method BaseMD. |
| 10152 | // When checking for overrides, the object object members are ignored. |
| 10153 | bool IsOverride(FunctionDecl *MD, FunctionDecl *BaseMD, |
| 10154 | bool UseMemberUsingDeclRules, bool ConsiderCudaAttrs = true); |
| 10155 | |
| 10156 | enum class AllowedExplicit { |
| 10157 | /// Allow no explicit functions to be used. |
| 10158 | None, |
| 10159 | /// Allow explicit conversion functions but not explicit constructors. |
| 10160 | Conversions, |
| 10161 | /// Allow both explicit conversion functions and explicit constructors. |
| 10162 | All |
| 10163 | }; |
| 10164 | |
| 10165 | ImplicitConversionSequence TryImplicitConversion( |
| 10166 | Expr *From, QualType ToType, bool SuppressUserConversions, |
| 10167 | AllowedExplicit AllowExplicit, bool InOverloadResolution, bool CStyle, |
| 10168 | bool AllowObjCWritebackConversion); |
| 10169 | |
| 10170 | /// PerformImplicitConversion - Perform an implicit conversion of the |
| 10171 | /// expression From to the type ToType. Returns the |
| 10172 | /// converted expression. Flavor is the kind of conversion we're |
| 10173 | /// performing, used in the error message. If @p AllowExplicit, |
| 10174 | /// explicit user-defined conversions are permitted. |
| 10175 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
| 10176 | AssignmentAction Action, |
| 10177 | bool AllowExplicit = false); |
| 10178 | |
| 10179 | /// IsIntegralPromotion - Determines whether the conversion from the |
| 10180 | /// expression From (whose potentially-adjusted type is FromType) to |
| 10181 | /// ToType is an integral promotion (C++ 4.5). If so, returns true and |
| 10182 | /// sets PromotedType to the promoted type. |
| 10183 | bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); |
| 10184 | |
| 10185 | /// IsFloatingPointPromotion - Determines whether the conversion from |
| 10186 | /// FromType to ToType is a floating point promotion (C++ 4.6). If so, |
| 10187 | /// returns true and sets PromotedType to the promoted type. |
| 10188 | bool IsFloatingPointPromotion(QualType FromType, QualType ToType); |
| 10189 | |
| 10190 | /// Determine if a conversion is a complex promotion. |
| 10191 | /// |
| 10192 | /// A complex promotion is defined as a complex -> complex conversion |
| 10193 | /// where the conversion between the underlying real types is a |
| 10194 | /// floating-point or integral promotion. |
| 10195 | bool IsComplexPromotion(QualType FromType, QualType ToType); |
| 10196 | |
| 10197 | /// IsOverflowBehaviorTypePromotion - Determines whether the conversion from |
| 10198 | /// FromType to ToType involves an OverflowBehaviorType FromType being |
| 10199 | /// promoted to an OverflowBehaviorType ToType which has a larger bitwidth. |
| 10200 | /// If so, returns true and sets FromType to ToType. |
| 10201 | bool IsOverflowBehaviorTypePromotion(QualType FromType, QualType ToType); |
| 10202 | |
| 10203 | /// IsOverflowBehaviorTypeConversion - Determines whether the conversion from |
| 10204 | /// FromType to ToType necessarily involves both an OverflowBehaviorType and |
| 10205 | /// a non-OverflowBehaviorType. If so, returns true and sets FromType to |
| 10206 | /// ToType. |
| 10207 | bool IsOverflowBehaviorTypeConversion(QualType FromType, QualType ToType); |
| 10208 | |
| 10209 | /// IsPointerConversion - Determines whether the conversion of the |
| 10210 | /// expression From, which has the (possibly adjusted) type FromType, |
| 10211 | /// can be converted to the type ToType via a pointer conversion (C++ |
| 10212 | /// 4.10). If so, returns true and places the converted type (that |
| 10213 | /// might differ from ToType in its cv-qualifiers at some level) into |
| 10214 | /// ConvertedType. |
| 10215 | /// |
| 10216 | /// This routine also supports conversions to and from block pointers |
| 10217 | /// and conversions with Objective-C's 'id', 'id<protocols...>', and |
| 10218 | /// pointers to interfaces. FIXME: Once we've determined the |
| 10219 | /// appropriate overloading rules for Objective-C, we may want to |
| 10220 | /// split the Objective-C checks into a different routine; however, |
| 10221 | /// GCC seems to consider all of these conversions to be pointer |
| 10222 | /// conversions, so for now they live here. IncompatibleObjC will be |
| 10223 | /// set if the conversion is an allowed Objective-C conversion that |
| 10224 | /// should result in a warning. |
| 10225 | bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, |
| 10226 | bool InOverloadResolution, QualType &ConvertedType, |
| 10227 | bool &IncompatibleObjC); |
| 10228 | |
| 10229 | /// isObjCPointerConversion - Determines whether this is an |
| 10230 | /// Objective-C pointer conversion. Subroutine of IsPointerConversion, |
| 10231 | /// with the same arguments and return values. |
| 10232 | bool isObjCPointerConversion(QualType FromType, QualType ToType, |
| 10233 | QualType &ConvertedType, bool &IncompatibleObjC); |
| 10234 | bool IsBlockPointerConversion(QualType FromType, QualType ToType, |
| 10235 | QualType &ConvertedType); |
| 10236 | |
| 10237 | /// FunctionParamTypesAreEqual - This routine checks two function proto types |
| 10238 | /// for equality of their parameter types. Caller has already checked that |
| 10239 | /// they have same number of parameters. If the parameters are different, |
| 10240 | /// ArgPos will have the parameter index of the first different parameter. |
| 10241 | /// If `Reversed` is true, the parameters of `NewType` will be compared in |
| 10242 | /// reverse order. That's useful if one of the functions is being used as a |
| 10243 | /// C++20 synthesized operator overload with a reversed parameter order. |
| 10244 | bool FunctionParamTypesAreEqual(ArrayRef<QualType> Old, |
| 10245 | ArrayRef<QualType> New, |
| 10246 | unsigned *ArgPos = nullptr, |
| 10247 | bool Reversed = false); |
| 10248 | |
| 10249 | bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType, |
| 10250 | const FunctionProtoType *NewType, |
| 10251 | unsigned *ArgPos = nullptr, |
| 10252 | bool Reversed = false); |
| 10253 | |
| 10254 | bool FunctionNonObjectParamTypesAreEqual(const FunctionDecl *OldFunction, |
| 10255 | const FunctionDecl *NewFunction, |
| 10256 | unsigned *ArgPos = nullptr, |
| 10257 | bool Reversed = false); |
| 10258 | |
| 10259 | /// HandleFunctionTypeMismatch - Gives diagnostic information for differeing |
| 10260 | /// function types. Catches different number of parameter, mismatch in |
| 10261 | /// parameter types, and different return types. |
| 10262 | void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, QualType FromType, |
| 10263 | QualType ToType); |
| 10264 | |
| 10265 | /// CheckPointerConversion - Check the pointer conversion from the |
| 10266 | /// expression From to the type ToType. This routine checks for |
| 10267 | /// ambiguous or inaccessible derived-to-base pointer |
| 10268 | /// conversions for which IsPointerConversion has already returned |
| 10269 | /// true. It returns true and produces a diagnostic if there was an |
| 10270 | /// error, or returns false otherwise. |
| 10271 | bool CheckPointerConversion(Expr *From, QualType ToType, CastKind &Kind, |
| 10272 | CXXCastPath &BasePath, bool IgnoreBaseAccess, |
| 10273 | bool Diagnose = true); |
| 10274 | |
| 10275 | /// IsMemberPointerConversion - Determines whether the conversion of the |
| 10276 | /// expression From, which has the (possibly adjusted) type FromType, can be |
| 10277 | /// converted to the type ToType via a member pointer conversion (C++ 4.11). |
| 10278 | /// If so, returns true and places the converted type (that might differ from |
| 10279 | /// ToType in its cv-qualifiers at some level) into ConvertedType. |
| 10280 | bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType, |
| 10281 | bool InOverloadResolution, |
| 10282 | QualType &ConvertedType); |
| 10283 | |
| 10284 | enum class MemberPointerConversionResult { |
| 10285 | Success, |
| 10286 | DifferentPointee, |
| 10287 | NotDerived, |
| 10288 | Ambiguous, |
| 10289 | Virtual, |
| 10290 | Inaccessible |
| 10291 | }; |
| 10292 | enum class MemberPointerConversionDirection : bool { Downcast, Upcast }; |
| 10293 | /// CheckMemberPointerConversion - Check the member pointer conversion from |
| 10294 | /// the expression From to the type ToType. This routine checks for ambiguous |
| 10295 | /// or virtual or inaccessible base-to-derived member pointer conversions for |
| 10296 | /// which IsMemberPointerConversion has already returned true. It produces a |
| 10297 | // diagnostic if there was an error. |
| 10298 | MemberPointerConversionResult CheckMemberPointerConversion( |
| 10299 | QualType FromType, const MemberPointerType *ToPtrType, CastKind &Kind, |
| 10300 | CXXCastPath &BasePath, SourceLocation CheckLoc, SourceRange OpRange, |
| 10301 | bool IgnoreBaseAccess, MemberPointerConversionDirection Direction); |
| 10302 | |
| 10303 | /// IsQualificationConversion - Determines whether the conversion from |
| 10304 | /// an rvalue of type FromType to ToType is a qualification conversion |
| 10305 | /// (C++ 4.4). |
| 10306 | /// |
| 10307 | /// \param ObjCLifetimeConversion Output parameter that will be set to |
| 10308 | /// indicate when the qualification conversion involves a change in the |
| 10309 | /// Objective-C object lifetime. |
| 10310 | bool IsQualificationConversion(QualType FromType, QualType ToType, |
| 10311 | bool CStyle, bool &ObjCLifetimeConversion); |
| 10312 | |
| 10313 | /// Determine whether the conversion from FromType to ToType is a valid |
| 10314 | /// conversion of ExtInfo/ExtProtoInfo on the nested function type. |
| 10315 | /// More precisely, this method checks whether FromType can be transformed |
| 10316 | /// into an exact match for ToType, by transforming its extended function |
| 10317 | /// type information in legal manner (e.g. by strictly stripping "noreturn" |
| 10318 | /// or "noexcept", or by stripping "noescape" for arguments). |
| 10319 | bool IsFunctionConversion(QualType FromType, QualType ToType) const; |
| 10320 | |
| 10321 | /// Same as `IsFunctionConversion`, but if this would return true, it sets |
| 10322 | /// `ResultTy` to `ToType`. |
| 10323 | bool TryFunctionConversion(QualType FromType, QualType ToType, |
| 10324 | QualType &ResultTy) const; |
| 10325 | |
| 10326 | bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType); |
| 10327 | void DiagnoseUseOfDeletedFunction(SourceLocation Loc, SourceRange Range, |
| 10328 | DeclarationName Name, |
| 10329 | OverloadCandidateSet &CandidateSet, |
| 10330 | FunctionDecl *Fn, MultiExprArg Args, |
| 10331 | bool IsMember = false); |
| 10332 | |
| 10333 | ExprResult InitializeExplicitObjectArgument(Sema &S, Expr *Obj, |
| 10334 | FunctionDecl *Fun); |
| 10335 | ExprResult PerformImplicitObjectArgumentInitialization( |
| 10336 | Expr *From, NestedNameSpecifier Qualifier, NamedDecl *FoundDecl, |
| 10337 | CXXMethodDecl *Method); |
| 10338 | |
| 10339 | /// PerformContextuallyConvertToBool - Perform a contextual conversion |
| 10340 | /// of the expression From to bool (C++0x [conv]p3). |
| 10341 | ExprResult PerformContextuallyConvertToBool(Expr *From); |
| 10342 | |
| 10343 | /// PerformContextuallyConvertToObjCPointer - Perform a contextual |
| 10344 | /// conversion of the expression From to an Objective-C pointer type. |
| 10345 | /// Returns a valid but null ExprResult if no conversion sequence exists. |
| 10346 | ExprResult PerformContextuallyConvertToObjCPointer(Expr *From); |
| 10347 | |
| 10348 | ExprResult BuildConvertedConstantExpression(Expr *From, QualType T, |
| 10349 | CCEKind CCE, |
| 10350 | NamedDecl *Dest = nullptr); |
| 10351 | |
| 10352 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
| 10353 | llvm::APSInt &Value, CCEKind CCE); |
| 10354 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
| 10355 | APValue &Value, CCEKind CCE, |
| 10356 | NamedDecl *Dest = nullptr); |
| 10357 | |
| 10358 | /// EvaluateConvertedConstantExpression - Evaluate an Expression |
| 10359 | /// That is a converted constant expression |
| 10360 | /// (which was built with BuildConvertedConstantExpression) |
| 10361 | ExprResult |
| 10362 | EvaluateConvertedConstantExpression(Expr *E, QualType T, APValue &Value, |
| 10363 | CCEKind CCE, bool RequireInt, |
| 10364 | const APValue &PreNarrowingValue); |
| 10365 | |
| 10366 | /// Abstract base class used to perform a contextual implicit |
| 10367 | /// conversion from an expression to any type passing a filter. |
| 10368 | class ContextualImplicitConverter { |
| 10369 | public: |
| 10370 | bool Suppress; |
| 10371 | bool SuppressConversion; |
| 10372 | |
| 10373 | ContextualImplicitConverter(bool Suppress = false, |
| 10374 | bool SuppressConversion = false) |
| 10375 | : Suppress(Suppress), SuppressConversion(SuppressConversion) {} |
| 10376 | |
| 10377 | /// Determine whether the specified type is a valid destination type |
| 10378 | /// for this conversion. |
| 10379 | virtual bool match(QualType T) = 0; |
| 10380 | |
| 10381 | /// Emits a diagnostic complaining that the expression does not have |
| 10382 | /// integral or enumeration type. |
| 10383 | virtual SemaDiagnosticBuilder diagnoseNoMatch(Sema &S, SourceLocation Loc, |
| 10384 | QualType T) = 0; |
| 10385 | |
| 10386 | /// Emits a diagnostic when the expression has incomplete class type. |
| 10387 | virtual SemaDiagnosticBuilder |
| 10388 | diagnoseIncomplete(Sema &S, SourceLocation Loc, QualType T) = 0; |
| 10389 | |
| 10390 | /// Emits a diagnostic when the only matching conversion function |
| 10391 | /// is explicit. |
| 10392 | virtual SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, |
| 10393 | SourceLocation Loc, |
| 10394 | QualType T, |
| 10395 | QualType ConvTy) = 0; |
| 10396 | |
| 10397 | /// Emits a note for the explicit conversion function. |
| 10398 | virtual SemaDiagnosticBuilder |
| 10399 | noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
| 10400 | |
| 10401 | /// Emits a diagnostic when there are multiple possible conversion |
| 10402 | /// functions. |
| 10403 | virtual SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 10404 | QualType T) = 0; |
| 10405 | |
| 10406 | /// Emits a note for one of the candidate conversions. |
| 10407 | virtual SemaDiagnosticBuilder |
| 10408 | noteAmbiguous(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
| 10409 | |
| 10410 | /// Emits a diagnostic when we picked a conversion function |
| 10411 | /// (for cases when we are not allowed to pick a conversion function). |
| 10412 | virtual SemaDiagnosticBuilder diagnoseConversion(Sema &S, |
| 10413 | SourceLocation Loc, |
| 10414 | QualType T, |
| 10415 | QualType ConvTy) = 0; |
| 10416 | |
| 10417 | virtual ~ContextualImplicitConverter() {} |
| 10418 | }; |
| 10419 | |
| 10420 | class ICEConvertDiagnoser : public ContextualImplicitConverter { |
| 10421 | bool AllowScopedEnumerations; |
| 10422 | |
| 10423 | public: |
| 10424 | ICEConvertDiagnoser(bool AllowScopedEnumerations, bool Suppress, |
| 10425 | bool SuppressConversion) |
| 10426 | : ContextualImplicitConverter(Suppress, SuppressConversion), |
| 10427 | AllowScopedEnumerations(AllowScopedEnumerations) {} |
| 10428 | |
| 10429 | /// Match an integral or (possibly scoped) enumeration type. |
| 10430 | bool match(QualType T) override; |
| 10431 | |
| 10432 | SemaDiagnosticBuilder diagnoseNoMatch(Sema &S, SourceLocation Loc, |
| 10433 | QualType T) override { |
| 10434 | return diagnoseNotInt(S, Loc, T); |
| 10435 | } |
| 10436 | |
| 10437 | /// Emits a diagnostic complaining that the expression does not have |
| 10438 | /// integral or enumeration type. |
| 10439 | virtual SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 10440 | QualType T) = 0; |
| 10441 | }; |
| 10442 | |
| 10443 | /// Perform a contextual implicit conversion. |
| 10444 | ExprResult |
| 10445 | PerformContextualImplicitConversion(SourceLocation Loc, Expr *FromE, |
| 10446 | ContextualImplicitConverter &Converter); |
| 10447 | |
| 10448 | /// ReferenceCompareResult - Expresses the result of comparing two |
| 10449 | /// types (cv1 T1 and cv2 T2) to determine their compatibility for the |
| 10450 | /// purposes of initialization by reference (C++ [dcl.init.ref]p4). |
| 10451 | enum ReferenceCompareResult { |
| 10452 | /// Ref_Incompatible - The two types are incompatible, so direct |
| 10453 | /// reference binding is not possible. |
| 10454 | Ref_Incompatible = 0, |
| 10455 | /// Ref_Related - The two types are reference-related, which means |
| 10456 | /// that their unqualified forms (T1 and T2) are either the same |
| 10457 | /// or T1 is a base class of T2. |
| 10458 | Ref_Related, |
| 10459 | /// Ref_Compatible - The two types are reference-compatible. |
| 10460 | Ref_Compatible |
| 10461 | }; |
| 10462 | |
| 10463 | // Fake up a scoped enumeration that still contextually converts to bool. |
| 10464 | struct ReferenceConversionsScope { |
| 10465 | /// The conversions that would be performed on an lvalue of type T2 when |
| 10466 | /// binding a reference of type T1 to it, as determined when evaluating |
| 10467 | /// whether T1 is reference-compatible with T2. |
| 10468 | enum ReferenceConversions { |
| 10469 | Qualification = 0x1, |
| 10470 | NestedQualification = 0x2, |
| 10471 | Function = 0x4, |
| 10472 | DerivedToBase = 0x8, |
| 10473 | ObjC = 0x10, |
| 10474 | ObjCLifetime = 0x20, |
| 10475 | |
| 10476 | LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/ObjCLifetime) |
| 10477 | }; |
| 10478 | }; |
| 10479 | using ReferenceConversions = ReferenceConversionsScope::ReferenceConversions; |
| 10480 | |
| 10481 | /// CompareReferenceRelationship - Compare the two types T1 and T2 to |
| 10482 | /// determine whether they are reference-compatible, |
| 10483 | /// reference-related, or incompatible, for use in C++ initialization by |
| 10484 | /// reference (C++ [dcl.ref.init]p4). Neither type can be a reference |
| 10485 | /// type, and the first type (T1) is the pointee type of the reference |
| 10486 | /// type being initialized. |
| 10487 | ReferenceCompareResult |
| 10488 | CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2, |
| 10489 | ReferenceConversions *Conv = nullptr); |
| 10490 | |
| 10491 | /// AddOverloadCandidate - Adds the given function to the set of |
| 10492 | /// candidate functions, using the given function call arguments. If |
| 10493 | /// @p SuppressUserConversions, then don't allow user-defined |
| 10494 | /// conversions via constructors or conversion operators. |
| 10495 | /// |
| 10496 | /// \param PartialOverloading true if we are performing "partial" overloading |
| 10497 | /// based on an incomplete set of function arguments. This feature is used by |
| 10498 | /// code completion. |
| 10499 | void AddOverloadCandidate( |
| 10500 | FunctionDecl *Function, DeclAccessPair FoundDecl, ArrayRef<Expr *> Args, |
| 10501 | OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false, |
| 10502 | bool PartialOverloading = false, bool AllowExplicit = true, |
| 10503 | bool AllowExplicitConversion = false, |
| 10504 | ADLCallKind IsADLCandidate = ADLCallKind::NotADL, |
| 10505 | ConversionSequenceList EarlyConversions = {}, |
| 10506 | OverloadCandidateParamOrder PO = {}, |
| 10507 | bool AggregateCandidateDeduction = false, bool StrictPackMatch = false); |
| 10508 | |
| 10509 | /// Add all of the function declarations in the given function set to |
| 10510 | /// the overload candidate set. |
| 10511 | void AddFunctionCandidates( |
| 10512 | const UnresolvedSetImpl &Functions, ArrayRef<Expr *> Args, |
| 10513 | OverloadCandidateSet &CandidateSet, |
| 10514 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
| 10515 | bool SuppressUserConversions = false, bool PartialOverloading = false, |
| 10516 | bool FirstArgumentIsBase = false); |
| 10517 | |
| 10518 | /// AddMethodCandidate - Adds a named decl (which is some kind of |
| 10519 | /// method) as a method candidate to the given overload set. |
| 10520 | void AddMethodCandidate(DeclAccessPair FoundDecl, QualType ObjectType, |
| 10521 | Expr::Classification ObjectClassification, |
| 10522 | ArrayRef<Expr *> Args, |
| 10523 | OverloadCandidateSet &CandidateSet, |
| 10524 | bool SuppressUserConversion = false, |
| 10525 | OverloadCandidateParamOrder PO = {}); |
| 10526 | |
| 10527 | /// AddMethodCandidate - Adds the given C++ member function to the set |
| 10528 | /// of candidate functions, using the given function call arguments |
| 10529 | /// and the object argument (@c Object). For example, in a call |
| 10530 | /// @c o.f(a1,a2), @c Object will contain @c o and @c Args will contain |
| 10531 | /// both @c a1 and @c a2. If @p SuppressUserConversions, then don't |
| 10532 | /// allow user-defined conversions via constructors or conversion |
| 10533 | /// operators. |
| 10534 | void AddMethodCandidate(CXXMethodDecl *Method, DeclAccessPair FoundDecl, |
| 10535 | CXXRecordDecl *ActingContext, QualType ObjectType, |
| 10536 | Expr::Classification ObjectClassification, |
| 10537 | ArrayRef<Expr *> Args, |
| 10538 | OverloadCandidateSet &CandidateSet, |
| 10539 | bool SuppressUserConversions = false, |
| 10540 | bool PartialOverloading = false, |
| 10541 | ConversionSequenceList EarlyConversions = {}, |
| 10542 | OverloadCandidateParamOrder PO = {}, |
| 10543 | bool StrictPackMatch = false); |
| 10544 | |
| 10545 | /// Add a C++ member function template as a candidate to the candidate |
| 10546 | /// set, using template argument deduction to produce an appropriate member |
| 10547 | /// function template specialization. |
| 10548 | void AddMethodTemplateCandidate( |
| 10549 | FunctionTemplateDecl *MethodTmpl, DeclAccessPair FoundDecl, |
| 10550 | CXXRecordDecl *ActingContext, |
| 10551 | TemplateArgumentListInfo *ExplicitTemplateArgs, QualType ObjectType, |
| 10552 | Expr::Classification ObjectClassification, ArrayRef<Expr *> Args, |
| 10553 | OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false, |
| 10554 | bool PartialOverloading = false, OverloadCandidateParamOrder PO = {}); |
| 10555 | |
| 10556 | /// Add a C++ function template specialization as a candidate |
| 10557 | /// in the candidate set, using template argument deduction to produce |
| 10558 | /// an appropriate function template specialization. |
| 10559 | void AddTemplateOverloadCandidate( |
| 10560 | FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, |
| 10561 | TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, |
| 10562 | OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false, |
| 10563 | bool PartialOverloading = false, bool AllowExplicit = true, |
| 10564 | ADLCallKind IsADLCandidate = ADLCallKind::NotADL, |
| 10565 | OverloadCandidateParamOrder PO = {}, |
| 10566 | bool AggregateCandidateDeduction = false); |
| 10567 | |
| 10568 | struct CheckNonDependentConversionsFlag { |
| 10569 | /// Do not consider any user-defined conversions when constructing the |
| 10570 | /// initializing sequence. |
| 10571 | bool SuppressUserConversions; |
| 10572 | |
| 10573 | /// Before constructing the initializing sequence, we check whether the |
| 10574 | /// parameter type and argument type contain any user defined conversions. |
| 10575 | /// If so, do not initialize them. This effectively bypasses some undesired |
| 10576 | /// instantiation before checking constaints, which might otherwise result |
| 10577 | /// in non-SFINAE errors e.g. recursive constraints. |
| 10578 | bool OnlyInitializeNonUserDefinedConversions; |
| 10579 | |
| 10580 | CheckNonDependentConversionsFlag( |
| 10581 | bool SuppressUserConversions, |
| 10582 | bool OnlyInitializeNonUserDefinedConversions) |
| 10583 | : SuppressUserConversions(SuppressUserConversions), |
| 10584 | OnlyInitializeNonUserDefinedConversions( |
| 10585 | OnlyInitializeNonUserDefinedConversions) {} |
| 10586 | }; |
| 10587 | |
| 10588 | /// Check that implicit conversion sequences can be formed for each argument |
| 10589 | /// whose corresponding parameter has a non-dependent type, per DR1391's |
| 10590 | /// [temp.deduct.call]p10. |
| 10591 | bool CheckNonDependentConversions( |
| 10592 | FunctionTemplateDecl *FunctionTemplate, ArrayRef<QualType> ParamTypes, |
| 10593 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet, |
| 10594 | ConversionSequenceList &Conversions, |
| 10595 | CheckNonDependentConversionsFlag UserConversionFlag, |
| 10596 | CXXRecordDecl *ActingContext = nullptr, QualType ObjectType = QualType(), |
| 10597 | Expr::Classification ObjectClassification = {}, |
| 10598 | OverloadCandidateParamOrder PO = {}); |
| 10599 | |
| 10600 | /// AddConversionCandidate - Add a C++ conversion function as a |
| 10601 | /// candidate in the candidate set (C++ [over.match.conv], |
| 10602 | /// C++ [over.match.copy]). From is the expression we're converting from, |
| 10603 | /// and ToType is the type that we're eventually trying to convert to |
| 10604 | /// (which may or may not be the same type as the type that the |
| 10605 | /// conversion function produces). |
| 10606 | void AddConversionCandidate( |
| 10607 | CXXConversionDecl *Conversion, DeclAccessPair FoundDecl, |
| 10608 | CXXRecordDecl *ActingContext, Expr *From, QualType ToType, |
| 10609 | OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, |
| 10610 | bool AllowExplicit, bool AllowResultConversion = true, |
| 10611 | bool StrictPackMatch = false); |
| 10612 | |
| 10613 | /// Adds a conversion function template specialization |
| 10614 | /// candidate to the overload set, using template argument deduction |
| 10615 | /// to deduce the template arguments of the conversion function |
| 10616 | /// template from the type that we are converting to (C++ |
| 10617 | /// [temp.deduct.conv]). |
| 10618 | void AddTemplateConversionCandidate( |
| 10619 | FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, |
| 10620 | CXXRecordDecl *ActingContext, Expr *From, QualType ToType, |
| 10621 | OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, |
| 10622 | bool AllowExplicit, bool AllowResultConversion = true); |
| 10623 | |
| 10624 | /// AddSurrogateCandidate - Adds a "surrogate" candidate function that |
| 10625 | /// converts the given @c Object to a function pointer via the |
| 10626 | /// conversion function @c Conversion, and then attempts to call it |
| 10627 | /// with the given arguments (C++ [over.call.object]p2-4). Proto is |
| 10628 | /// the type of function that we'll eventually be calling. |
| 10629 | void AddSurrogateCandidate(CXXConversionDecl *Conversion, |
| 10630 | DeclAccessPair FoundDecl, |
| 10631 | CXXRecordDecl *ActingContext, |
| 10632 | const FunctionProtoType *Proto, Expr *Object, |
| 10633 | ArrayRef<Expr *> Args, |
| 10634 | OverloadCandidateSet &CandidateSet); |
| 10635 | |
| 10636 | /// Add all of the non-member operator function declarations in the given |
| 10637 | /// function set to the overload candidate set. |
| 10638 | void AddNonMemberOperatorCandidates( |
| 10639 | const UnresolvedSetImpl &Functions, ArrayRef<Expr *> Args, |
| 10640 | OverloadCandidateSet &CandidateSet, |
| 10641 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); |
| 10642 | |
| 10643 | /// Add overload candidates for overloaded operators that are |
| 10644 | /// member functions. |
| 10645 | /// |
| 10646 | /// Add the overloaded operator candidates that are member functions |
| 10647 | /// for the operator Op that was used in an operator expression such |
| 10648 | /// as "x Op y". , Args/NumArgs provides the operator arguments, and |
| 10649 | /// CandidateSet will store the added overload candidates. (C++ |
| 10650 | /// [over.match.oper]). |
| 10651 | void AddMemberOperatorCandidates(OverloadedOperatorKind Op, |
| 10652 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
| 10653 | OverloadCandidateSet &CandidateSet, |
| 10654 | OverloadCandidateParamOrder PO = {}); |
| 10655 | |
| 10656 | /// AddBuiltinCandidate - Add a candidate for a built-in |
| 10657 | /// operator. ResultTy and ParamTys are the result and parameter types |
| 10658 | /// of the built-in candidate, respectively. Args and NumArgs are the |
| 10659 | /// arguments being passed to the candidate. IsAssignmentOperator |
| 10660 | /// should be true when this built-in candidate is an assignment |
| 10661 | /// operator. NumContextualBoolArguments is the number of arguments |
| 10662 | /// (at the beginning of the argument list) that will be contextually |
| 10663 | /// converted to bool. |
| 10664 | void AddBuiltinCandidate(QualType *ParamTys, ArrayRef<Expr *> Args, |
| 10665 | OverloadCandidateSet &CandidateSet, |
| 10666 | bool IsAssignmentOperator = false, |
| 10667 | unsigned NumContextualBoolArguments = 0); |
| 10668 | |
| 10669 | /// AddBuiltinOperatorCandidates - Add the appropriate built-in |
| 10670 | /// operator overloads to the candidate set (C++ [over.built]), based |
| 10671 | /// on the operator @p Op and the arguments given. For example, if the |
| 10672 | /// operator is a binary '+', this routine might add "int |
| 10673 | /// operator+(int, int)" to cover integer addition. |
| 10674 | void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, |
| 10675 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
| 10676 | OverloadCandidateSet &CandidateSet); |
| 10677 | |
| 10678 | /// Add function candidates found via argument-dependent lookup |
| 10679 | /// to the set of overloading candidates. |
| 10680 | /// |
| 10681 | /// This routine performs argument-dependent name lookup based on the |
| 10682 | /// given function name (which may also be an operator name) and adds |
| 10683 | /// all of the overload candidates found by ADL to the overload |
| 10684 | /// candidate set (C++ [basic.lookup.argdep]). |
| 10685 | void AddArgumentDependentLookupCandidates( |
| 10686 | DeclarationName Name, SourceLocation Loc, ArrayRef<Expr *> Args, |
| 10687 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
| 10688 | OverloadCandidateSet &CandidateSet, bool PartialOverloading = false); |
| 10689 | |
| 10690 | /// Check the enable_if expressions on the given function. Returns the first |
| 10691 | /// failing attribute, or NULL if they were all successful. |
| 10692 | EnableIfAttr *CheckEnableIf(FunctionDecl *Function, SourceLocation CallLoc, |
| 10693 | ArrayRef<Expr *> Args, |
| 10694 | bool MissingImplicitThis = false); |
| 10695 | |
| 10696 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
| 10697 | /// non-ArgDependent DiagnoseIfAttrs. |
| 10698 | /// |
| 10699 | /// Argument-dependent diagnose_if attributes should be checked each time a |
| 10700 | /// function is used as a direct callee of a function call. |
| 10701 | /// |
| 10702 | /// Returns true if any errors were emitted. |
| 10703 | bool diagnoseArgDependentDiagnoseIfAttrs(const FunctionDecl *Function, |
| 10704 | const Expr *ThisArg, |
| 10705 | ArrayRef<const Expr *> Args, |
| 10706 | SourceLocation Loc); |
| 10707 | |
| 10708 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
| 10709 | /// ArgDependent DiagnoseIfAttrs. |
| 10710 | /// |
| 10711 | /// Argument-independent diagnose_if attributes should be checked on every use |
| 10712 | /// of a function. |
| 10713 | /// |
| 10714 | /// Returns true if any errors were emitted. |
| 10715 | bool diagnoseArgIndependentDiagnoseIfAttrs(const NamedDecl *ND, |
| 10716 | SourceLocation Loc); |
| 10717 | |
| 10718 | /// Determine if \p A and \p B are equivalent internal linkage declarations |
| 10719 | /// from different modules, and thus an ambiguity error can be downgraded to |
| 10720 | /// an extension warning. |
| 10721 | bool isEquivalentInternalLinkageDeclaration(const NamedDecl *A, |
| 10722 | const NamedDecl *B); |
| 10723 | void diagnoseEquivalentInternalLinkageDeclarations( |
| 10724 | SourceLocation Loc, const NamedDecl *D, |
| 10725 | ArrayRef<const NamedDecl *> Equiv); |
| 10726 | |
| 10727 | // Emit as a 'note' the specific overload candidate |
| 10728 | void NoteOverloadCandidate( |
| 10729 | const NamedDecl *Found, const FunctionDecl *Fn, |
| 10730 | OverloadCandidateRewriteKind RewriteKind = OverloadCandidateRewriteKind(), |
| 10731 | QualType DestType = QualType(), bool TakingAddress = false); |
| 10732 | |
| 10733 | // Emit as a series of 'note's all template and non-templates identified by |
| 10734 | // the expression Expr |
| 10735 | void NoteAllOverloadCandidates(Expr *E, QualType DestType = QualType(), |
| 10736 | bool TakingAddress = false); |
| 10737 | |
| 10738 | /// Returns whether the given function's address can be taken or not, |
| 10739 | /// optionally emitting a diagnostic if the address can't be taken. |
| 10740 | /// |
| 10741 | /// Returns false if taking the address of the function is illegal. |
| 10742 | bool checkAddressOfFunctionIsAvailable(const FunctionDecl *Function, |
| 10743 | bool Complain = false, |
| 10744 | SourceLocation Loc = SourceLocation()); |
| 10745 | |
| 10746 | // [PossiblyAFunctionType] --> [Return] |
| 10747 | // NonFunctionType --> NonFunctionType |
| 10748 | // R (A) --> R(A) |
| 10749 | // R (*)(A) --> R (A) |
| 10750 | // R (&)(A) --> R (A) |
| 10751 | // R (S::*)(A) --> R (A) |
| 10752 | QualType (QualType PossiblyAFunctionType); |
| 10753 | |
| 10754 | /// ResolveAddressOfOverloadedFunction - Try to resolve the address of |
| 10755 | /// an overloaded function (C++ [over.over]), where @p From is an |
| 10756 | /// expression with overloaded function type and @p ToType is the type |
| 10757 | /// we're trying to resolve to. For example: |
| 10758 | /// |
| 10759 | /// @code |
| 10760 | /// int f(double); |
| 10761 | /// int f(int); |
| 10762 | /// |
| 10763 | /// int (*pfd)(double) = f; // selects f(double) |
| 10764 | /// @endcode |
| 10765 | /// |
| 10766 | /// This routine returns the resulting FunctionDecl if it could be |
| 10767 | /// resolved, and NULL otherwise. When @p Complain is true, this |
| 10768 | /// routine will emit diagnostics if there is an error. |
| 10769 | FunctionDecl * |
| 10770 | ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, QualType TargetType, |
| 10771 | bool Complain, DeclAccessPair &Found, |
| 10772 | bool *pHadMultipleCandidates = nullptr); |
| 10773 | |
| 10774 | /// Given an expression that refers to an overloaded function, try to |
| 10775 | /// resolve that function to a single function that can have its address |
| 10776 | /// taken. This will modify `Pair` iff it returns non-null. |
| 10777 | /// |
| 10778 | /// This routine can only succeed if from all of the candidates in the |
| 10779 | /// overload set for SrcExpr that can have their addresses taken, there is one |
| 10780 | /// candidate that is more constrained than the rest. |
| 10781 | FunctionDecl * |
| 10782 | resolveAddressOfSingleOverloadCandidate(Expr *E, DeclAccessPair &FoundResult); |
| 10783 | |
| 10784 | /// Given an overloaded function, tries to turn it into a non-overloaded |
| 10785 | /// function reference using resolveAddressOfSingleOverloadCandidate. This |
| 10786 | /// will perform access checks, diagnose the use of the resultant decl, and, |
| 10787 | /// if requested, potentially perform a function-to-pointer decay. |
| 10788 | /// |
| 10789 | /// Returns false if resolveAddressOfSingleOverloadCandidate fails. |
| 10790 | /// Otherwise, returns true. This may emit diagnostics and return true. |
| 10791 | bool resolveAndFixAddressOfSingleOverloadCandidate( |
| 10792 | ExprResult &SrcExpr, bool DoFunctionPointerConversion = false); |
| 10793 | |
| 10794 | /// Given an expression that refers to an overloaded function, try to |
| 10795 | /// resolve that overloaded function expression down to a single function. |
| 10796 | /// |
| 10797 | /// This routine can only resolve template-ids that refer to a single function |
| 10798 | /// template, where that template-id refers to a single template whose |
| 10799 | /// template arguments are either provided by the template-id or have |
| 10800 | /// defaults, as described in C++0x [temp.arg.explicit]p3. |
| 10801 | /// |
| 10802 | /// If no template-ids are found, no diagnostics are emitted and NULL is |
| 10803 | /// returned. |
| 10804 | FunctionDecl *ResolveSingleFunctionTemplateSpecialization( |
| 10805 | OverloadExpr *ovl, bool Complain = false, DeclAccessPair *Found = nullptr, |
| 10806 | TemplateSpecCandidateSet *FailedTSC = nullptr, |
| 10807 | bool ForTypeDeduction = false); |
| 10808 | |
| 10809 | // Resolve and fix an overloaded expression that can be resolved |
| 10810 | // because it identifies a single function template specialization. |
| 10811 | // |
| 10812 | // Last three arguments should only be supplied if Complain = true |
| 10813 | // |
| 10814 | // Return true if it was logically possible to so resolve the |
| 10815 | // expression, regardless of whether or not it succeeded. Always |
| 10816 | // returns true if 'complain' is set. |
| 10817 | bool ResolveAndFixSingleFunctionTemplateSpecialization( |
| 10818 | ExprResult &SrcExpr, bool DoFunctionPointerConversion = false, |
| 10819 | bool Complain = false, SourceRange OpRangeForComplaining = SourceRange(), |
| 10820 | QualType DestTypeForComplaining = QualType(), |
| 10821 | unsigned DiagIDForComplaining = 0); |
| 10822 | |
| 10823 | /// Add the overload candidates named by callee and/or found by argument |
| 10824 | /// dependent lookup to the given overload set. |
| 10825 | void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE, |
| 10826 | ArrayRef<Expr *> Args, |
| 10827 | OverloadCandidateSet &CandidateSet, |
| 10828 | bool PartialOverloading = false); |
| 10829 | |
| 10830 | /// Add the call candidates from the given set of lookup results to the given |
| 10831 | /// overload set. Non-function lookup results are ignored. |
| 10832 | void AddOverloadedCallCandidates( |
| 10833 | LookupResult &R, TemplateArgumentListInfo *ExplicitTemplateArgs, |
| 10834 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet); |
| 10835 | |
| 10836 | // An enum used to represent the different possible results of building a |
| 10837 | // range-based for loop. |
| 10838 | enum ForRangeStatus { |
| 10839 | FRS_Success, |
| 10840 | FRS_NoViableFunction, |
| 10841 | FRS_DiagnosticIssued |
| 10842 | }; |
| 10843 | |
| 10844 | /// Build a call to 'begin' or 'end' for a C++11 for-range statement. If the |
| 10845 | /// given LookupResult is non-empty, it is assumed to describe a member which |
| 10846 | /// will be invoked. Otherwise, the function will be found via argument |
| 10847 | /// dependent lookup. |
| 10848 | /// CallExpr is set to a valid expression and FRS_Success returned on success, |
| 10849 | /// otherwise CallExpr is set to ExprError() and some non-success value |
| 10850 | /// is returned. |
| 10851 | ForRangeStatus BuildForRangeBeginEndCall(SourceLocation Loc, |
| 10852 | SourceLocation RangeLoc, |
| 10853 | const DeclarationNameInfo &NameInfo, |
| 10854 | LookupResult &MemberLookup, |
| 10855 | OverloadCandidateSet *CandidateSet, |
| 10856 | Expr *Range, ExprResult *CallExpr); |
| 10857 | |
| 10858 | /// BuildOverloadedCallExpr - Given the call expression that calls Fn |
| 10859 | /// (which eventually refers to the declaration Func) and the call |
| 10860 | /// arguments Args/NumArgs, attempt to resolve the function call down |
| 10861 | /// to a specific function. If overload resolution succeeds, returns |
| 10862 | /// the call expression produced by overload resolution. |
| 10863 | /// Otherwise, emits diagnostics and returns ExprError. |
| 10864 | ExprResult BuildOverloadedCallExpr( |
| 10865 | Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE, SourceLocation LParenLoc, |
| 10866 | MultiExprArg Args, SourceLocation RParenLoc, Expr *ExecConfig, |
| 10867 | bool AllowTypoCorrection = true, bool CalleesAddressIsTaken = false); |
| 10868 | |
| 10869 | /// Constructs and populates an OverloadedCandidateSet from |
| 10870 | /// the given function. |
| 10871 | /// \returns true when an the ExprResult output parameter has been set. |
| 10872 | bool buildOverloadedCallSet(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE, |
| 10873 | MultiExprArg Args, SourceLocation RParenLoc, |
| 10874 | OverloadCandidateSet *CandidateSet, |
| 10875 | ExprResult *Result); |
| 10876 | |
| 10877 | ExprResult CreateUnresolvedLookupExpr(CXXRecordDecl *NamingClass, |
| 10878 | NestedNameSpecifierLoc NNSLoc, |
| 10879 | DeclarationNameInfo DNI, |
| 10880 | const UnresolvedSetImpl &Fns, |
| 10881 | bool PerformADL = true); |
| 10882 | |
| 10883 | /// Create a unary operation that may resolve to an overloaded |
| 10884 | /// operator. |
| 10885 | /// |
| 10886 | /// \param OpLoc The location of the operator itself (e.g., '*'). |
| 10887 | /// |
| 10888 | /// \param Opc The UnaryOperatorKind that describes this operator. |
| 10889 | /// |
| 10890 | /// \param Fns The set of non-member functions that will be |
| 10891 | /// considered by overload resolution. The caller needs to build this |
| 10892 | /// set based on the context using, e.g., |
| 10893 | /// LookupOverloadedOperatorName() and ArgumentDependentLookup(). This |
| 10894 | /// set should not contain any member functions; those will be added |
| 10895 | /// by CreateOverloadedUnaryOp(). |
| 10896 | /// |
| 10897 | /// \param Input The input argument. |
| 10898 | ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, |
| 10899 | UnaryOperatorKind Opc, |
| 10900 | const UnresolvedSetImpl &Fns, Expr *input, |
| 10901 | bool RequiresADL = true); |
| 10902 | |
| 10903 | /// Perform lookup for an overloaded binary operator. |
| 10904 | void LookupOverloadedBinOp(OverloadCandidateSet &CandidateSet, |
| 10905 | OverloadedOperatorKind Op, |
| 10906 | const UnresolvedSetImpl &Fns, |
| 10907 | ArrayRef<Expr *> Args, bool RequiresADL = true); |
| 10908 | |
| 10909 | /// Create a binary operation that may resolve to an overloaded |
| 10910 | /// operator. |
| 10911 | /// |
| 10912 | /// \param OpLoc The location of the operator itself (e.g., '+'). |
| 10913 | /// |
| 10914 | /// \param Opc The BinaryOperatorKind that describes this operator. |
| 10915 | /// |
| 10916 | /// \param Fns The set of non-member functions that will be |
| 10917 | /// considered by overload resolution. The caller needs to build this |
| 10918 | /// set based on the context using, e.g., |
| 10919 | /// LookupOverloadedOperatorName() and ArgumentDependentLookup(). This |
| 10920 | /// set should not contain any member functions; those will be added |
| 10921 | /// by CreateOverloadedBinOp(). |
| 10922 | /// |
| 10923 | /// \param LHS Left-hand argument. |
| 10924 | /// \param RHS Right-hand argument. |
| 10925 | /// \param PerformADL Whether to consider operator candidates found by ADL. |
| 10926 | /// \param AllowRewrittenCandidates Whether to consider candidates found by |
| 10927 | /// C++20 operator rewrites. |
| 10928 | /// \param DefaultedFn If we are synthesizing a defaulted operator function, |
| 10929 | /// the function in question. Such a function is never a candidate in |
| 10930 | /// our overload resolution. This also enables synthesizing a three-way |
| 10931 | /// comparison from < and == as described in C++20 [class.spaceship]p1. |
| 10932 | ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, |
| 10933 | const UnresolvedSetImpl &Fns, Expr *LHS, |
| 10934 | Expr *RHS, bool RequiresADL = true, |
| 10935 | bool AllowRewrittenCandidates = true, |
| 10936 | FunctionDecl *DefaultedFn = nullptr); |
| 10937 | ExprResult BuildSynthesizedThreeWayComparison(SourceLocation OpLoc, |
| 10938 | const UnresolvedSetImpl &Fns, |
| 10939 | Expr *LHS, Expr *RHS, |
| 10940 | FunctionDecl *DefaultedFn); |
| 10941 | |
| 10942 | ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, |
| 10943 | SourceLocation RLoc, Expr *Base, |
| 10944 | MultiExprArg Args); |
| 10945 | |
| 10946 | /// BuildCallToMemberFunction - Build a call to a member |
| 10947 | /// function. MemExpr is the expression that refers to the member |
| 10948 | /// function (and includes the object parameter), Args/NumArgs are the |
| 10949 | /// arguments to the function call (not including the object |
| 10950 | /// parameter). The caller needs to validate that the member |
| 10951 | /// expression refers to a non-static member function or an overloaded |
| 10952 | /// member function. |
| 10953 | ExprResult BuildCallToMemberFunction( |
| 10954 | Scope *S, Expr *MemExpr, SourceLocation LParenLoc, MultiExprArg Args, |
| 10955 | SourceLocation RParenLoc, Expr *ExecConfig = nullptr, |
| 10956 | bool IsExecConfig = false, bool AllowRecovery = false); |
| 10957 | |
| 10958 | /// BuildCallToObjectOfClassType - Build a call to an object of class |
| 10959 | /// type (C++ [over.call.object]), which can end up invoking an |
| 10960 | /// overloaded function call operator (@c operator()) or performing a |
| 10961 | /// user-defined conversion on the object argument. |
| 10962 | ExprResult BuildCallToObjectOfClassType(Scope *S, Expr *Object, |
| 10963 | SourceLocation LParenLoc, |
| 10964 | MultiExprArg Args, |
| 10965 | SourceLocation RParenLoc); |
| 10966 | |
| 10967 | /// BuildOverloadedArrowExpr - Build a call to an overloaded @c operator-> |
| 10968 | /// (if one exists), where @c Base is an expression of class type and |
| 10969 | /// @c Member is the name of the member we're trying to find. |
| 10970 | ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, |
| 10971 | SourceLocation OpLoc, |
| 10972 | bool *NoArrowOperatorFound = nullptr); |
| 10973 | |
| 10974 | ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, |
| 10975 | CXXConversionDecl *Method, |
| 10976 | bool HadMultipleCandidates); |
| 10977 | |
| 10978 | /// BuildLiteralOperatorCall - Build a UserDefinedLiteral by creating a call |
| 10979 | /// to a literal operator described by the provided lookup results. |
| 10980 | ExprResult BuildLiteralOperatorCall( |
| 10981 | LookupResult &R, DeclarationNameInfo &SuffixInfo, ArrayRef<Expr *> Args, |
| 10982 | SourceLocation LitEndLoc, |
| 10983 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); |
| 10984 | |
| 10985 | /// FixOverloadedFunctionReference - E is an expression that refers to |
| 10986 | /// a C++ overloaded function (possibly with some parentheses and |
| 10987 | /// perhaps a '&' around it). We have resolved the overloaded function |
| 10988 | /// to the function declaration Fn, so patch up the expression E to |
| 10989 | /// refer (possibly indirectly) to Fn. Returns the new expr. |
| 10990 | ExprResult FixOverloadedFunctionReference(Expr *E, DeclAccessPair FoundDecl, |
| 10991 | FunctionDecl *Fn); |
| 10992 | ExprResult FixOverloadedFunctionReference(ExprResult, |
| 10993 | DeclAccessPair FoundDecl, |
| 10994 | FunctionDecl *Fn); |
| 10995 | |
| 10996 | /// - Returns a selector which best matches given argument list or |
| 10997 | /// nullptr if none could be found |
| 10998 | ObjCMethodDecl *SelectBestMethod(Selector Sel, MultiExprArg Args, |
| 10999 | bool IsInstance, |
| 11000 | SmallVectorImpl<ObjCMethodDecl *> &Methods); |
| 11001 | |
| 11002 | ///@} |
| 11003 | |
| 11004 | // |
| 11005 | // |
| 11006 | // ------------------------------------------------------------------------- |
| 11007 | // |
| 11008 | // |
| 11009 | |
| 11010 | /// \name Statements |
| 11011 | /// Implementations are in SemaStmt.cpp |
| 11012 | ///@{ |
| 11013 | |
| 11014 | public: |
| 11015 | /// Stack of active SEH __finally scopes. Can be empty. |
| 11016 | SmallVector<Scope *, 2> CurrentSEHFinally; |
| 11017 | |
| 11018 | /// Stack of '_Defer' statements that are currently being parsed, as well |
| 11019 | /// as the locations of their '_Defer' keywords. Can be empty. |
| 11020 | SmallVector<std::pair<Scope *, SourceLocation>, 2> CurrentDefer; |
| 11021 | |
| 11022 | StmtResult ActOnExprStmt(ExprResult Arg, bool DiscardedValue = true); |
| 11023 | StmtResult ActOnExprStmtError(); |
| 11024 | |
| 11025 | StmtResult ActOnNullStmt(SourceLocation SemiLoc, |
| 11026 | bool HasLeadingEmptyMacro = false); |
| 11027 | |
| 11028 | StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, |
| 11029 | SourceLocation EndLoc); |
| 11030 | void ActOnForEachDeclStmt(DeclGroupPtrTy Decl); |
| 11031 | |
| 11032 | /// DiagnoseUnusedExprResult - If the statement passed in is an expression |
| 11033 | /// whose result is unused, warn. |
| 11034 | void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID); |
| 11035 | |
| 11036 | void ActOnStartOfCompoundStmt(bool IsStmtExpr); |
| 11037 | void ActOnAfterCompoundStatementLeadingPragmas(); |
| 11038 | void ActOnFinishOfCompoundStmt(); |
| 11039 | StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, |
| 11040 | ArrayRef<Stmt *> Elts, bool isStmtExpr); |
| 11041 | |
| 11042 | sema::CompoundScopeInfo &getCurCompoundScope() const; |
| 11043 | |
| 11044 | ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val); |
| 11045 | StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, |
| 11046 | SourceLocation DotDotDotLoc, ExprResult RHS, |
| 11047 | SourceLocation ColonLoc); |
| 11048 | |
| 11049 | /// ActOnCaseStmtBody - This installs a statement as the body of a case. |
| 11050 | void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt); |
| 11051 | |
| 11052 | StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, |
| 11053 | SourceLocation ColonLoc, Stmt *SubStmt, |
| 11054 | Scope *CurScope); |
| 11055 | StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, |
| 11056 | SourceLocation ColonLoc, Stmt *SubStmt); |
| 11057 | |
| 11058 | StmtResult BuildAttributedStmt(SourceLocation AttrsLoc, |
| 11059 | ArrayRef<const Attr *> Attrs, Stmt *SubStmt); |
| 11060 | StmtResult ActOnAttributedStmt(const ParsedAttributes &AttrList, |
| 11061 | Stmt *SubStmt); |
| 11062 | |
| 11063 | /// Check whether the given statement can have musttail applied to it, |
| 11064 | /// issuing a diagnostic and returning false if not. In the success case, |
| 11065 | /// the statement is rewritten to remove implicit nodes from the return |
| 11066 | /// value. |
| 11067 | bool checkAndRewriteMustTailAttr(Stmt *St, const Attr &MTA); |
| 11068 | |
| 11069 | StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, |
| 11070 | SourceLocation LParenLoc, Stmt *InitStmt, |
| 11071 | ConditionResult Cond, SourceLocation RParenLoc, |
| 11072 | Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal); |
| 11073 | StmtResult BuildIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, |
| 11074 | SourceLocation LParenLoc, Stmt *InitStmt, |
| 11075 | ConditionResult Cond, SourceLocation RParenLoc, |
| 11076 | Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal); |
| 11077 | |
| 11078 | ExprResult CheckSwitchCondition(SourceLocation SwitchLoc, Expr *Cond); |
| 11079 | |
| 11080 | StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, |
| 11081 | SourceLocation LParenLoc, Stmt *InitStmt, |
| 11082 | ConditionResult Cond, |
| 11083 | SourceLocation RParenLoc); |
| 11084 | StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, |
| 11085 | Stmt *Body); |
| 11086 | |
| 11087 | /// DiagnoseAssignmentEnum - Warn if assignment to enum is a constant |
| 11088 | /// integer not in the range of enum values. |
| 11089 | void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, |
| 11090 | Expr *SrcExpr); |
| 11091 | |
| 11092 | StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 11093 | ConditionResult Cond, SourceLocation RParenLoc, |
| 11094 | Stmt *Body); |
| 11095 | StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, |
| 11096 | SourceLocation WhileLoc, SourceLocation CondLParen, |
| 11097 | Expr *Cond, SourceLocation CondRParen); |
| 11098 | |
| 11099 | StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
| 11100 | Stmt *First, ConditionResult Second, |
| 11101 | FullExprArg Third, SourceLocation RParenLoc, |
| 11102 | Stmt *Body); |
| 11103 | |
| 11104 | /// In an Objective C collection iteration statement: |
| 11105 | /// for (x in y) |
| 11106 | /// x can be an arbitrary l-value expression. Bind it up as a |
| 11107 | /// full-expression. |
| 11108 | StmtResult ActOnForEachLValueExpr(Expr *E); |
| 11109 | |
| 11110 | enum BuildForRangeKind { |
| 11111 | /// Initial building of a for-range statement. |
| 11112 | BFRK_Build, |
| 11113 | /// Instantiation or recovery rebuild of a for-range statement. Don't |
| 11114 | /// attempt any typo-correction. |
| 11115 | BFRK_Rebuild, |
| 11116 | /// Determining whether a for-range statement could be built. Avoid any |
| 11117 | /// unnecessary or irreversible actions. |
| 11118 | BFRK_Check |
| 11119 | }; |
| 11120 | |
| 11121 | /// ActOnCXXForRangeStmt - Check and build a C++11 for-range statement. |
| 11122 | /// |
| 11123 | /// C++11 [stmt.ranged]: |
| 11124 | /// A range-based for statement is equivalent to |
| 11125 | /// |
| 11126 | /// { |
| 11127 | /// auto && __range = range-init; |
| 11128 | /// for ( auto __begin = begin-expr, |
| 11129 | /// __end = end-expr; |
| 11130 | /// __begin != __end; |
| 11131 | /// ++__begin ) { |
| 11132 | /// for-range-declaration = *__begin; |
| 11133 | /// statement |
| 11134 | /// } |
| 11135 | /// } |
| 11136 | /// |
| 11137 | /// The body of the loop is not available yet, since it cannot be analysed |
| 11138 | /// until we have determined the type of the for-range-declaration. |
| 11139 | StmtResult ActOnCXXForRangeStmt( |
| 11140 | Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc, |
| 11141 | Stmt *InitStmt, Stmt *LoopVar, SourceLocation ColonLoc, Expr *Collection, |
| 11142 | SourceLocation RParenLoc, BuildForRangeKind Kind, |
| 11143 | ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps = {}); |
| 11144 | |
| 11145 | /// BuildCXXForRangeStmt - Build or instantiate a C++11 for-range statement. |
| 11146 | StmtResult BuildCXXForRangeStmt( |
| 11147 | SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt, |
| 11148 | SourceLocation ColonLoc, Stmt *RangeDecl, Stmt *Begin, Stmt *End, |
| 11149 | Expr *Cond, Expr *Inc, Stmt *LoopVarDecl, SourceLocation RParenLoc, |
| 11150 | BuildForRangeKind Kind, |
| 11151 | ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps = {}); |
| 11152 | |
| 11153 | /// FinishCXXForRangeStmt - Attach the body to a C++0x for-range statement. |
| 11154 | /// This is a separate step from ActOnCXXForRangeStmt because analysis of the |
| 11155 | /// body cannot be performed until after the type of the range variable is |
| 11156 | /// determined. |
| 11157 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body); |
| 11158 | |
| 11159 | StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 11160 | LabelDecl *TheDecl); |
| 11161 | StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, |
| 11162 | SourceLocation StarLoc, Expr *DestExp); |
| 11163 | StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope, |
| 11164 | LabelDecl *Label, SourceLocation LabelLoc); |
| 11165 | StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope, |
| 11166 | LabelDecl *Label, SourceLocation LabelLoc); |
| 11167 | |
| 11168 | void ActOnStartOfDeferStmt(SourceLocation DeferLoc, Scope *CurScope); |
| 11169 | void ActOnDeferStmtError(Scope *CurScope); |
| 11170 | StmtResult ActOnEndOfDeferStmt(Stmt *Body, Scope *CurScope); |
| 11171 | |
| 11172 | struct NamedReturnInfo { |
| 11173 | const VarDecl *Candidate; |
| 11174 | |
| 11175 | enum Status : uint8_t { None, MoveEligible, MoveEligibleAndCopyElidable }; |
| 11176 | Status S; |
| 11177 | |
| 11178 | bool isMoveEligible() const { return S != None; }; |
| 11179 | bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; } |
| 11180 | }; |
| 11181 | enum class SimplerImplicitMoveMode { ForceOff, Normal, ForceOn }; |
| 11182 | |
| 11183 | /// Determine whether the given expression might be move-eligible or |
| 11184 | /// copy-elidable in either a (co_)return statement or throw expression, |
| 11185 | /// without considering function return type, if applicable. |
| 11186 | /// |
| 11187 | /// \param E The expression being returned from the function or block, |
| 11188 | /// being thrown, or being co_returned from a coroutine. This expression |
| 11189 | /// might be modified by the implementation. |
| 11190 | /// |
| 11191 | /// \param Mode Overrides detection of current language mode |
| 11192 | /// and uses the rules for C++23. |
| 11193 | /// |
| 11194 | /// \returns An aggregate which contains the Candidate and isMoveEligible |
| 11195 | /// and isCopyElidable methods. If Candidate is non-null, it means |
| 11196 | /// isMoveEligible() would be true under the most permissive language |
| 11197 | /// standard. |
| 11198 | NamedReturnInfo getNamedReturnInfo( |
| 11199 | Expr *&E, SimplerImplicitMoveMode Mode = SimplerImplicitMoveMode::Normal); |
| 11200 | |
| 11201 | /// Determine whether the given NRVO candidate variable is move-eligible or |
| 11202 | /// copy-elidable, without considering function return type. |
| 11203 | /// |
| 11204 | /// \param VD The NRVO candidate variable. |
| 11205 | /// |
| 11206 | /// \returns An aggregate which contains the Candidate and isMoveEligible |
| 11207 | /// and isCopyElidable methods. If Candidate is non-null, it means |
| 11208 | /// isMoveEligible() would be true under the most permissive language |
| 11209 | /// standard. |
| 11210 | NamedReturnInfo getNamedReturnInfo(const VarDecl *VD); |
| 11211 | |
| 11212 | /// Updates given NamedReturnInfo's move-eligible and |
| 11213 | /// copy-elidable statuses, considering the function |
| 11214 | /// return type criteria as applicable to return statements. |
| 11215 | /// |
| 11216 | /// \param Info The NamedReturnInfo object to update. |
| 11217 | /// |
| 11218 | /// \param ReturnType This is the return type of the function. |
| 11219 | /// \returns The copy elision candidate, in case the initial return expression |
| 11220 | /// was copy elidable, or nullptr otherwise. |
| 11221 | const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info, |
| 11222 | QualType ReturnType); |
| 11223 | |
| 11224 | /// Perform the initialization of a potentially-movable value, which |
| 11225 | /// is the result of return value. |
| 11226 | /// |
| 11227 | /// This routine implements C++20 [class.copy.elision]p3, which attempts to |
| 11228 | /// treat returned lvalues as rvalues in certain cases (to prefer move |
| 11229 | /// construction), then falls back to treating them as lvalues if that failed. |
| 11230 | ExprResult |
| 11231 | PerformMoveOrCopyInitialization(const InitializedEntity &Entity, |
| 11232 | const NamedReturnInfo &NRInfo, Expr *Value, |
| 11233 | bool SupressSimplerImplicitMoves = false); |
| 11234 | |
| 11235 | TypeLoc getReturnTypeLoc(FunctionDecl *FD) const; |
| 11236 | |
| 11237 | /// Deduce the return type for a function from a returned expression, per |
| 11238 | /// C++1y [dcl.spec.auto]p6. |
| 11239 | bool DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD, |
| 11240 | SourceLocation ReturnLoc, Expr *RetExpr, |
| 11241 | const AutoType *AT); |
| 11242 | |
| 11243 | StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
| 11244 | Scope *CurScope); |
| 11245 | StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
| 11246 | bool AllowRecovery = false); |
| 11247 | |
| 11248 | /// ActOnCapScopeReturnStmt - Utility routine to type-check return statements |
| 11249 | /// for capturing scopes. |
| 11250 | StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
| 11251 | NamedReturnInfo &NRInfo, |
| 11252 | bool SupressSimplerImplicitMoves); |
| 11253 | |
| 11254 | /// ActOnCXXCatchBlock - Takes an exception declaration and a handler block |
| 11255 | /// and creates a proper catch handler from them. |
| 11256 | StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, Decl *ExDecl, |
| 11257 | Stmt *HandlerBlock); |
| 11258 | |
| 11259 | /// ActOnCXXTryBlock - Takes a try compound-statement and a number of |
| 11260 | /// handlers and creates a try statement from them. |
| 11261 | StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, |
| 11262 | ArrayRef<Stmt *> Handlers); |
| 11263 | |
| 11264 | void DiagnoseExceptionUse(SourceLocation Loc, bool IsTry); |
| 11265 | |
| 11266 | StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ? |
| 11267 | SourceLocation TryLoc, Stmt *TryBlock, |
| 11268 | Stmt *Handler); |
| 11269 | StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, |
| 11270 | Stmt *Block); |
| 11271 | void ActOnStartSEHFinallyBlock(); |
| 11272 | void ActOnAbortSEHFinallyBlock(); |
| 11273 | StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block); |
| 11274 | StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope); |
| 11275 | |
| 11276 | StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
| 11277 | bool IsIfExists, |
| 11278 | NestedNameSpecifierLoc QualifierLoc, |
| 11279 | DeclarationNameInfo NameInfo, |
| 11280 | Stmt *Nested); |
| 11281 | StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, |
| 11282 | bool IsIfExists, CXXScopeSpec &SS, |
| 11283 | UnqualifiedId &Name, Stmt *Nested); |
| 11284 | |
| 11285 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
| 11286 | CapturedRegionKind Kind, unsigned NumParams); |
| 11287 | typedef std::pair<StringRef, QualType> CapturedParamNameType; |
| 11288 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
| 11289 | CapturedRegionKind Kind, |
| 11290 | ArrayRef<CapturedParamNameType> Params, |
| 11291 | unsigned OpenMPCaptureLevel = 0); |
| 11292 | StmtResult ActOnCapturedRegionEnd(Stmt *S); |
| 11293 | void ActOnCapturedRegionError(); |
| 11294 | RecordDecl *CreateCapturedStmtRecordDecl(CapturedDecl *&CD, |
| 11295 | SourceLocation Loc, |
| 11296 | unsigned NumParams); |
| 11297 | |
| 11298 | private: |
| 11299 | /// Check whether the given statement can have musttail applied to it, |
| 11300 | /// issuing a diagnostic and returning false if not. |
| 11301 | bool checkMustTailAttr(const Stmt *St, const Attr &MTA); |
| 11302 | |
| 11303 | /// Check if the given expression contains 'break' or 'continue' |
| 11304 | /// statement that produces control flow different from GCC. |
| 11305 | void CheckBreakContinueBinding(Expr *E); |
| 11306 | |
| 11307 | ///@} |
| 11308 | |
| 11309 | // |
| 11310 | // |
| 11311 | // ------------------------------------------------------------------------- |
| 11312 | // |
| 11313 | // |
| 11314 | |
| 11315 | /// \name `inline asm` Statement |
| 11316 | /// Implementations are in SemaStmtAsm.cpp |
| 11317 | ///@{ |
| 11318 | |
| 11319 | public: |
| 11320 | ExprResult ActOnGCCAsmStmtString(Expr *Stm, bool ForAsmLabel); |
| 11321 | StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
| 11322 | bool IsVolatile, unsigned NumOutputs, |
| 11323 | unsigned NumInputs, IdentifierInfo **Names, |
| 11324 | MultiExprArg Constraints, MultiExprArg Exprs, |
| 11325 | Expr *AsmString, MultiExprArg Clobbers, |
| 11326 | unsigned NumLabels, SourceLocation RParenLoc); |
| 11327 | |
| 11328 | void FillInlineAsmIdentifierInfo(Expr *Res, |
| 11329 | llvm::InlineAsmIdentifierInfo &Info); |
| 11330 | ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS, |
| 11331 | SourceLocation TemplateKWLoc, |
| 11332 | UnqualifiedId &Id, |
| 11333 | bool IsUnevaluatedContext); |
| 11334 | bool LookupInlineAsmField(StringRef Base, StringRef Member, unsigned &Offset, |
| 11335 | SourceLocation AsmLoc); |
| 11336 | ExprResult LookupInlineAsmVarDeclField(Expr *RefExpr, StringRef Member, |
| 11337 | SourceLocation AsmLoc); |
| 11338 | StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
| 11339 | ArrayRef<Token> AsmToks, StringRef AsmString, |
| 11340 | unsigned NumOutputs, unsigned NumInputs, |
| 11341 | ArrayRef<StringRef> Constraints, |
| 11342 | ArrayRef<StringRef> Clobbers, |
| 11343 | ArrayRef<Expr *> Exprs, SourceLocation EndLoc); |
| 11344 | LabelDecl *GetOrCreateMSAsmLabel(StringRef ExternalLabelName, |
| 11345 | SourceLocation Location, bool AlwaysCreate); |
| 11346 | |
| 11347 | ///@} |
| 11348 | |
| 11349 | // |
| 11350 | // |
| 11351 | // ------------------------------------------------------------------------- |
| 11352 | // |
| 11353 | // |
| 11354 | |
| 11355 | /// \name Statement Attribute Handling |
| 11356 | /// Implementations are in SemaStmtAttr.cpp |
| 11357 | ///@{ |
| 11358 | |
| 11359 | public: |
| 11360 | bool CheckNoInlineAttr(const Stmt *OrigSt, const Stmt *CurSt, |
| 11361 | const AttributeCommonInfo &A); |
| 11362 | bool CheckAlwaysInlineAttr(const Stmt *OrigSt, const Stmt *CurSt, |
| 11363 | const AttributeCommonInfo &A); |
| 11364 | |
| 11365 | CodeAlignAttr *BuildCodeAlignAttr(const AttributeCommonInfo &CI, Expr *E); |
| 11366 | bool CheckRebuiltStmtAttributes(ArrayRef<const Attr *> Attrs); |
| 11367 | |
| 11368 | /// Process the attributes before creating an attributed statement. Returns |
| 11369 | /// the semantic attributes that have been processed. |
| 11370 | void ProcessStmtAttributes(Stmt *Stmt, const ParsedAttributes &InAttrs, |
| 11371 | SmallVectorImpl<const Attr *> &OutAttrs); |
| 11372 | |
| 11373 | ExprResult ActOnCXXAssumeAttr(Stmt *St, const ParsedAttr &A, |
| 11374 | SourceRange Range); |
| 11375 | ExprResult BuildCXXAssumeExpr(Expr *Assumption, |
| 11376 | const IdentifierInfo *AttrName, |
| 11377 | SourceRange Range); |
| 11378 | |
| 11379 | ///@} |
| 11380 | |
| 11381 | // |
| 11382 | // |
| 11383 | // ------------------------------------------------------------------------- |
| 11384 | // |
| 11385 | // |
| 11386 | |
| 11387 | /// \name C++ Templates |
| 11388 | /// Implementations are in SemaTemplate.cpp |
| 11389 | ///@{ |
| 11390 | |
| 11391 | public: |
| 11392 | // Saves the current floating-point pragma stack and clear it in this Sema. |
| 11393 | class FpPragmaStackSaveRAII { |
| 11394 | public: |
| 11395 | FpPragmaStackSaveRAII(Sema &S) |
| 11396 | : S(S), SavedStack(std::move(S.FpPragmaStack)) { |
| 11397 | S.FpPragmaStack.Stack.clear(); |
| 11398 | } |
| 11399 | ~FpPragmaStackSaveRAII() { S.FpPragmaStack = std::move(SavedStack); } |
| 11400 | FpPragmaStackSaveRAII(const FpPragmaStackSaveRAII &) = delete; |
| 11401 | FpPragmaStackSaveRAII &operator=(const FpPragmaStackSaveRAII &) = delete; |
| 11402 | |
| 11403 | private: |
| 11404 | Sema &S; |
| 11405 | PragmaStack<FPOptionsOverride> SavedStack; |
| 11406 | }; |
| 11407 | |
| 11408 | void resetFPOptions(FPOptions FPO) { |
| 11409 | CurFPFeatures = FPO; |
| 11410 | FpPragmaStack.CurrentValue = FPO.getChangesFrom(Base: FPOptions(LangOpts)); |
| 11411 | } |
| 11412 | |
| 11413 | ArrayRef<InventedTemplateParameterInfo> getInventedParameterInfos() const { |
| 11414 | return llvm::ArrayRef(InventedParameterInfos.begin() + |
| 11415 | InventedParameterInfosStart, |
| 11416 | InventedParameterInfos.end()); |
| 11417 | } |
| 11418 | |
| 11419 | ArrayRef<sema::FunctionScopeInfo *> getFunctionScopes() const { |
| 11420 | return llvm::ArrayRef(FunctionScopes.begin() + FunctionScopesStart, |
| 11421 | FunctionScopes.end()); |
| 11422 | } |
| 11423 | |
| 11424 | typedef llvm::MapVector<const FunctionDecl *, |
| 11425 | std::unique_ptr<LateParsedTemplate>> |
| 11426 | LateParsedTemplateMapT; |
| 11427 | LateParsedTemplateMapT LateParsedTemplateMap; |
| 11428 | |
| 11429 | /// Determine the number of levels of enclosing template parameters. This is |
| 11430 | /// only usable while parsing. Note that this does not include dependent |
| 11431 | /// contexts in which no template parameters have yet been declared, such as |
| 11432 | /// in a terse function template or generic lambda before the first 'auto' is |
| 11433 | /// encountered. |
| 11434 | unsigned getTemplateDepth(Scope *S) const; |
| 11435 | |
| 11436 | void FilterAcceptableTemplateNames(LookupResult &R, |
| 11437 | bool AllowFunctionTemplates = true, |
| 11438 | bool AllowDependent = true); |
| 11439 | bool hasAnyAcceptableTemplateNames(LookupResult &R, |
| 11440 | bool AllowFunctionTemplates = true, |
| 11441 | bool AllowDependent = true, |
| 11442 | bool AllowNonTemplateFunctions = false); |
| 11443 | /// Try to interpret the lookup result D as a template-name. |
| 11444 | /// |
| 11445 | /// \param D A declaration found by name lookup. |
| 11446 | /// \param AllowFunctionTemplates Whether function templates should be |
| 11447 | /// considered valid results. |
| 11448 | /// \param AllowDependent Whether unresolved using declarations (that might |
| 11449 | /// name templates) should be considered valid results. |
| 11450 | static NamedDecl *getAsTemplateNameDecl(NamedDecl *D, |
| 11451 | bool AllowFunctionTemplates = true, |
| 11452 | bool AllowDependent = true); |
| 11453 | |
| 11454 | enum TemplateNameIsRequiredTag { TemplateNameIsRequired }; |
| 11455 | /// Whether and why a template name is required in this lookup. |
| 11456 | class RequiredTemplateKind { |
| 11457 | public: |
| 11458 | /// Template name is required if TemplateKWLoc is valid. |
| 11459 | RequiredTemplateKind(SourceLocation TemplateKWLoc = SourceLocation()) |
| 11460 | : TemplateKW(TemplateKWLoc) {} |
| 11461 | /// Template name is unconditionally required. |
| 11462 | RequiredTemplateKind(TemplateNameIsRequiredTag) {} |
| 11463 | |
| 11464 | SourceLocation getTemplateKeywordLoc() const { |
| 11465 | return TemplateKW.value_or(u: SourceLocation()); |
| 11466 | } |
| 11467 | bool hasTemplateKeyword() const { |
| 11468 | return getTemplateKeywordLoc().isValid(); |
| 11469 | } |
| 11470 | bool isRequired() const { return TemplateKW != SourceLocation(); } |
| 11471 | explicit operator bool() const { return isRequired(); } |
| 11472 | |
| 11473 | private: |
| 11474 | std::optional<SourceLocation> TemplateKW; |
| 11475 | }; |
| 11476 | |
| 11477 | enum class AssumedTemplateKind { |
| 11478 | /// This is not assumed to be a template name. |
| 11479 | None, |
| 11480 | /// This is assumed to be a template name because lookup found nothing. |
| 11481 | FoundNothing, |
| 11482 | /// This is assumed to be a template name because lookup found one or more |
| 11483 | /// functions (but no function templates). |
| 11484 | FoundFunctions, |
| 11485 | }; |
| 11486 | |
| 11487 | bool |
| 11488 | LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS, |
| 11489 | QualType ObjectType, bool EnteringContext, |
| 11490 | RequiredTemplateKind RequiredTemplate = SourceLocation(), |
| 11491 | AssumedTemplateKind *ATK = nullptr, |
| 11492 | bool AllowTypoCorrection = true); |
| 11493 | |
| 11494 | TemplateNameKind isTemplateName(Scope *S, CXXScopeSpec &SS, |
| 11495 | bool hasTemplateKeyword, |
| 11496 | const UnqualifiedId &Name, |
| 11497 | ParsedType ObjectType, bool EnteringContext, |
| 11498 | TemplateTy &Template, |
| 11499 | bool &MemberOfUnknownSpecialization, |
| 11500 | bool Disambiguation = false); |
| 11501 | |
| 11502 | /// Try to resolve an undeclared template name as a type template. |
| 11503 | /// |
| 11504 | /// Sets II to the identifier corresponding to the template name, and updates |
| 11505 | /// Name to a corresponding (typo-corrected) type template name and TNK to |
| 11506 | /// the corresponding kind, if possible. |
| 11507 | void ActOnUndeclaredTypeTemplateName(Scope *S, TemplateTy &Name, |
| 11508 | TemplateNameKind &TNK, |
| 11509 | SourceLocation NameLoc, |
| 11510 | IdentifierInfo *&II); |
| 11511 | |
| 11512 | /// Determine whether a particular identifier might be the name in a C++1z |
| 11513 | /// deduction-guide declaration. |
| 11514 | bool isDeductionGuideName(Scope *S, const IdentifierInfo &Name, |
| 11515 | SourceLocation NameLoc, CXXScopeSpec &SS, |
| 11516 | ParsedTemplateTy *Template = nullptr); |
| 11517 | |
| 11518 | bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, |
| 11519 | SourceLocation IILoc, Scope *S, |
| 11520 | const CXXScopeSpec *SS, |
| 11521 | TemplateTy &SuggestedTemplate, |
| 11522 | TemplateNameKind &SuggestedKind); |
| 11523 | |
| 11524 | /// Determine whether we would be unable to instantiate this template (because |
| 11525 | /// it either has no definition, or is in the process of being instantiated). |
| 11526 | bool DiagnoseUninstantiableTemplate( |
| 11527 | SourceLocation PointOfInstantiation, NamedDecl *Instantiation, |
| 11528 | bool InstantiatedFromMember, const NamedDecl *Pattern, |
| 11529 | const NamedDecl *PatternDef, TemplateSpecializationKind TSK, |
| 11530 | bool Complain = true, bool *Unreachable = nullptr); |
| 11531 | |
| 11532 | /// DiagnoseTemplateParameterShadow - Produce a diagnostic complaining |
| 11533 | /// that the template parameter 'PrevDecl' is being shadowed by a new |
| 11534 | /// declaration at location Loc. Returns true to indicate that this is |
| 11535 | /// an error, and false otherwise. |
| 11536 | /// |
| 11537 | /// \param Loc The location of the declaration that shadows a template |
| 11538 | /// parameter. |
| 11539 | /// |
| 11540 | /// \param PrevDecl The template parameter that the declaration shadows. |
| 11541 | /// |
| 11542 | /// \param SupportedForCompatibility Whether to issue the diagnostic as |
| 11543 | /// a warning for compatibility with older versions of clang. |
| 11544 | /// Ignored when MSVC compatibility is enabled. |
| 11545 | void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl, |
| 11546 | bool SupportedForCompatibility = false); |
| 11547 | |
| 11548 | /// AdjustDeclIfTemplate - If the given decl happens to be a template, reset |
| 11549 | /// the parameter D to reference the templated declaration and return a |
| 11550 | /// pointer to the template declaration. Otherwise, do nothing to D and return |
| 11551 | /// null. |
| 11552 | TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); |
| 11553 | |
| 11554 | /// ActOnTypeParameter - Called when a C++ template type parameter |
| 11555 | /// (e.g., "typename T") has been parsed. Typename specifies whether |
| 11556 | /// the keyword "typename" was used to declare the type parameter |
| 11557 | /// (otherwise, "class" was used), and KeyLoc is the location of the |
| 11558 | /// "class" or "typename" keyword. ParamName is the name of the |
| 11559 | /// parameter (NULL indicates an unnamed template parameter) and |
| 11560 | /// ParamNameLoc is the location of the parameter name (if any). |
| 11561 | /// If the type parameter has a default argument, it will be added |
| 11562 | /// later via ActOnTypeParameterDefault. |
| 11563 | NamedDecl *ActOnTypeParameter(Scope *S, bool Typename, |
| 11564 | SourceLocation EllipsisLoc, |
| 11565 | SourceLocation KeyLoc, |
| 11566 | IdentifierInfo *ParamName, |
| 11567 | SourceLocation ParamNameLoc, unsigned Depth, |
| 11568 | unsigned Position, SourceLocation EqualLoc, |
| 11569 | ParsedType DefaultArg, bool HasTypeConstraint); |
| 11570 | |
| 11571 | bool CheckTypeConstraint(TemplateIdAnnotation *TypeConstraint); |
| 11572 | |
| 11573 | bool ActOnTypeConstraint(const CXXScopeSpec &SS, |
| 11574 | TemplateIdAnnotation *TypeConstraint, |
| 11575 | TemplateTypeParmDecl *ConstrainedParameter, |
| 11576 | SourceLocation EllipsisLoc); |
| 11577 | bool BuildTypeConstraint(const CXXScopeSpec &SS, |
| 11578 | TemplateIdAnnotation *TypeConstraint, |
| 11579 | TemplateTypeParmDecl *ConstrainedParameter, |
| 11580 | SourceLocation EllipsisLoc, |
| 11581 | bool AllowUnexpandedPack); |
| 11582 | |
| 11583 | /// Attach a type-constraint to a template parameter. |
| 11584 | /// \returns true if an error occurred. This can happen if the |
| 11585 | /// immediately-declared constraint could not be formed (e.g. incorrect number |
| 11586 | /// of arguments for the named concept). |
| 11587 | bool AttachTypeConstraint(NestedNameSpecifierLoc NS, |
| 11588 | DeclarationNameInfo NameInfo, |
| 11589 | TemplateDecl *NamedConcept, NamedDecl *FoundDecl, |
| 11590 | const TemplateArgumentListInfo *TemplateArgs, |
| 11591 | TemplateTypeParmDecl *ConstrainedParameter, |
| 11592 | SourceLocation EllipsisLoc); |
| 11593 | |
| 11594 | bool AttachTypeConstraint(AutoTypeLoc TL, |
| 11595 | NonTypeTemplateParmDecl *NewConstrainedParm, |
| 11596 | NonTypeTemplateParmDecl *OrigConstrainedParm, |
| 11597 | SourceLocation EllipsisLoc); |
| 11598 | |
| 11599 | /// Require the given type to be a structural type, and diagnose if it is not. |
| 11600 | /// |
| 11601 | /// \return \c true if an error was produced. |
| 11602 | bool RequireStructuralType(QualType T, SourceLocation Loc); |
| 11603 | |
| 11604 | /// Check that the type of a non-type template parameter is |
| 11605 | /// well-formed. |
| 11606 | /// |
| 11607 | /// \returns the (possibly-promoted) parameter type if valid; |
| 11608 | /// otherwise, produces a diagnostic and returns a NULL type. |
| 11609 | QualType CheckNonTypeTemplateParameterType(TypeSourceInfo *&TSI, |
| 11610 | SourceLocation Loc); |
| 11611 | QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); |
| 11612 | |
| 11613 | NamedDecl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, |
| 11614 | unsigned Depth, unsigned Position, |
| 11615 | SourceLocation EqualLoc, |
| 11616 | Expr *DefaultArg); |
| 11617 | |
| 11618 | /// ActOnTemplateTemplateParameter - Called when a C++ template template |
| 11619 | /// parameter (e.g. T in template <template \<typename> class T> class array) |
| 11620 | /// has been parsed. S is the current scope. |
| 11621 | NamedDecl *ActOnTemplateTemplateParameter( |
| 11622 | Scope *S, SourceLocation TmpLoc, TemplateNameKind Kind, |
| 11623 | bool TypenameKeyword, TemplateParameterList *Params, |
| 11624 | SourceLocation EllipsisLoc, IdentifierInfo *ParamName, |
| 11625 | SourceLocation ParamNameLoc, unsigned Depth, unsigned Position, |
| 11626 | SourceLocation EqualLoc, ParsedTemplateArgument DefaultArg); |
| 11627 | |
| 11628 | /// ActOnTemplateParameterList - Builds a TemplateParameterList, optionally |
| 11629 | /// constrained by RequiresClause, that contains the template parameters in |
| 11630 | /// Params. |
| 11631 | TemplateParameterList *ActOnTemplateParameterList( |
| 11632 | unsigned Depth, SourceLocation ExportLoc, SourceLocation TemplateLoc, |
| 11633 | SourceLocation LAngleLoc, ArrayRef<NamedDecl *> Params, |
| 11634 | SourceLocation RAngleLoc, Expr *RequiresClause); |
| 11635 | |
| 11636 | /// The context in which we are checking a template parameter list. |
| 11637 | enum TemplateParamListContext { |
| 11638 | // For this context, Class, Variable, TypeAlias, and non-pack Template |
| 11639 | // Template Parameters are treated uniformly. |
| 11640 | TPC_Other, |
| 11641 | |
| 11642 | TPC_FunctionTemplate, |
| 11643 | TPC_ClassTemplateMember, |
| 11644 | TPC_FriendClassTemplate, |
| 11645 | TPC_FriendFunctionTemplate, |
| 11646 | TPC_FriendFunctionTemplateDefinition, |
| 11647 | TPC_TemplateTemplateParameterPack, |
| 11648 | }; |
| 11649 | |
| 11650 | /// Checks the validity of a template parameter list, possibly |
| 11651 | /// considering the template parameter list from a previous |
| 11652 | /// declaration. |
| 11653 | /// |
| 11654 | /// If an "old" template parameter list is provided, it must be |
| 11655 | /// equivalent (per TemplateParameterListsAreEqual) to the "new" |
| 11656 | /// template parameter list. |
| 11657 | /// |
| 11658 | /// \param NewParams Template parameter list for a new template |
| 11659 | /// declaration. This template parameter list will be updated with any |
| 11660 | /// default arguments that are carried through from the previous |
| 11661 | /// template parameter list. |
| 11662 | /// |
| 11663 | /// \param OldParams If provided, template parameter list from a |
| 11664 | /// previous declaration of the same template. Default template |
| 11665 | /// arguments will be merged from the old template parameter list to |
| 11666 | /// the new template parameter list. |
| 11667 | /// |
| 11668 | /// \param TPC Describes the context in which we are checking the given |
| 11669 | /// template parameter list. |
| 11670 | /// |
| 11671 | /// \param SkipBody If we might have already made a prior merged definition |
| 11672 | /// of this template visible, the corresponding body-skipping information. |
| 11673 | /// Default argument redefinition is not an error when skipping such a body, |
| 11674 | /// because (under the ODR) we can assume the default arguments are the same |
| 11675 | /// as the prior merged definition. |
| 11676 | /// |
| 11677 | /// \returns true if an error occurred, false otherwise. |
| 11678 | bool CheckTemplateParameterList(TemplateParameterList *NewParams, |
| 11679 | TemplateParameterList *OldParams, |
| 11680 | TemplateParamListContext TPC, |
| 11681 | SkipBodyInfo *SkipBody = nullptr); |
| 11682 | |
| 11683 | /// Match the given template parameter lists to the given scope |
| 11684 | /// specifier, returning the template parameter list that applies to the |
| 11685 | /// name. |
| 11686 | /// |
| 11687 | /// \param DeclStartLoc the start of the declaration that has a scope |
| 11688 | /// specifier or a template parameter list. |
| 11689 | /// |
| 11690 | /// \param DeclLoc The location of the declaration itself. |
| 11691 | /// |
| 11692 | /// \param SS the scope specifier that will be matched to the given template |
| 11693 | /// parameter lists. This scope specifier precedes a qualified name that is |
| 11694 | /// being declared. |
| 11695 | /// |
| 11696 | /// \param TemplateId The template-id following the scope specifier, if there |
| 11697 | /// is one. Used to check for a missing 'template<>'. |
| 11698 | /// |
| 11699 | /// \param ParamLists the template parameter lists, from the outermost to the |
| 11700 | /// innermost template parameter lists. |
| 11701 | /// |
| 11702 | /// \param IsFriend Whether to apply the slightly different rules for |
| 11703 | /// matching template parameters to scope specifiers in friend |
| 11704 | /// declarations. |
| 11705 | /// |
| 11706 | /// \param IsMemberSpecialization will be set true if the scope specifier |
| 11707 | /// denotes a fully-specialized type, and therefore this is a declaration of |
| 11708 | /// a member specialization. |
| 11709 | /// |
| 11710 | /// \returns the template parameter list, if any, that corresponds to the |
| 11711 | /// name that is preceded by the scope specifier @p SS. This template |
| 11712 | /// parameter list may have template parameters (if we're declaring a |
| 11713 | /// template) or may have no template parameters (if we're declaring a |
| 11714 | /// template specialization), or may be NULL (if what we're declaring isn't |
| 11715 | /// itself a template). |
| 11716 | TemplateParameterList *MatchTemplateParametersToScopeSpecifier( |
| 11717 | SourceLocation DeclStartLoc, SourceLocation DeclLoc, |
| 11718 | const CXXScopeSpec &SS, TemplateIdAnnotation *TemplateId, |
| 11719 | ArrayRef<TemplateParameterList *> ParamLists, bool IsFriend, |
| 11720 | bool &IsMemberSpecialization, bool &Invalid, |
| 11721 | bool SuppressDiagnostic = false); |
| 11722 | |
| 11723 | /// Returns the template parameter list with all default template argument |
| 11724 | /// information. |
| 11725 | TemplateParameterList *GetTemplateParameterList(TemplateDecl *TD); |
| 11726 | |
| 11727 | DeclResult CheckClassTemplate( |
| 11728 | Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, |
| 11729 | CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc, |
| 11730 | const ParsedAttributesView &Attr, TemplateParameterList *TemplateParams, |
| 11731 | AccessSpecifier AS, SourceLocation ModulePrivateLoc, |
| 11732 | SourceLocation FriendLoc, unsigned NumOuterTemplateParamLists, |
| 11733 | TemplateParameterList **OuterTemplateParamLists, |
| 11734 | SkipBodyInfo *SkipBody = nullptr); |
| 11735 | |
| 11736 | /// Translates template arguments as provided by the parser |
| 11737 | /// into template arguments used by semantic analysis. |
| 11738 | void translateTemplateArguments(const ASTTemplateArgsPtr &In, |
| 11739 | TemplateArgumentListInfo &Out); |
| 11740 | |
| 11741 | /// Convert a parsed type into a parsed template argument. This is mostly |
| 11742 | /// trivial, except that we may have parsed a C++17 deduced class template |
| 11743 | /// specialization type, in which case we should form a template template |
| 11744 | /// argument instead of a type template argument. |
| 11745 | ParsedTemplateArgument ActOnTemplateTypeArgument(TypeResult ParsedType); |
| 11746 | |
| 11747 | void NoteAllFoundTemplates(TemplateName Name); |
| 11748 | |
| 11749 | QualType CheckTemplateIdType(ElaboratedTypeKeyword Keyword, |
| 11750 | TemplateName Template, |
| 11751 | SourceLocation TemplateLoc, |
| 11752 | TemplateArgumentListInfo &TemplateArgs, |
| 11753 | Scope *Scope, bool ForNestedNameSpecifier); |
| 11754 | |
| 11755 | TypeResult |
| 11756 | ActOnTemplateIdType(Scope *S, ElaboratedTypeKeyword ElaboratedKeyword, |
| 11757 | SourceLocation ElaboratedKeywordLoc, CXXScopeSpec &SS, |
| 11758 | SourceLocation TemplateKWLoc, TemplateTy Template, |
| 11759 | const IdentifierInfo *TemplateII, |
| 11760 | SourceLocation TemplateIILoc, SourceLocation LAngleLoc, |
| 11761 | ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc, |
| 11762 | bool IsCtorOrDtorName = false, bool IsClassName = false, |
| 11763 | ImplicitTypenameContext AllowImplicitTypename = |
| 11764 | ImplicitTypenameContext::No); |
| 11765 | |
| 11766 | /// Parsed an elaborated-type-specifier that refers to a template-id, |
| 11767 | /// such as \c class T::template apply<U>. |
| 11768 | TypeResult ActOnTagTemplateIdType( |
| 11769 | TagUseKind TUK, TypeSpecifierType TagSpec, SourceLocation TagLoc, |
| 11770 | CXXScopeSpec &SS, SourceLocation TemplateKWLoc, TemplateTy TemplateD, |
| 11771 | SourceLocation TemplateLoc, SourceLocation LAngleLoc, |
| 11772 | ASTTemplateArgsPtr TemplateArgsIn, SourceLocation RAngleLoc); |
| 11773 | |
| 11774 | DeclResult ActOnVarTemplateSpecialization( |
| 11775 | Scope *S, Declarator &D, TypeSourceInfo *TSI, LookupResult &Previous, |
| 11776 | SourceLocation TemplateKWLoc, TemplateParameterList *TemplateParams, |
| 11777 | StorageClass SC, bool IsPartialSpecialization); |
| 11778 | |
| 11779 | /// Get the specialization of the given variable template corresponding to |
| 11780 | /// the specified argument list, or a null-but-valid result if the arguments |
| 11781 | /// are dependent. |
| 11782 | DeclResult CheckVarTemplateId(VarTemplateDecl *Template, |
| 11783 | SourceLocation TemplateLoc, |
| 11784 | SourceLocation TemplateNameLoc, |
| 11785 | const TemplateArgumentListInfo &TemplateArgs, |
| 11786 | bool SetWrittenArgs); |
| 11787 | |
| 11788 | /// Form a reference to the specialization of the given variable template |
| 11789 | /// corresponding to the specified argument list, or a null-but-valid result |
| 11790 | /// if the arguments are dependent. |
| 11791 | ExprResult CheckVarTemplateId(const CXXScopeSpec &SS, |
| 11792 | const DeclarationNameInfo &NameInfo, |
| 11793 | VarTemplateDecl *Template, NamedDecl *FoundD, |
| 11794 | SourceLocation TemplateLoc, |
| 11795 | const TemplateArgumentListInfo *TemplateArgs); |
| 11796 | |
| 11797 | ExprResult CheckVarOrConceptTemplateTemplateId( |
| 11798 | const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, |
| 11799 | TemplateTemplateParmDecl *Template, SourceLocation TemplateLoc, |
| 11800 | const TemplateArgumentListInfo *TemplateArgs); |
| 11801 | |
| 11802 | ExprResult |
| 11803 | CheckConceptTemplateId(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
| 11804 | const DeclarationNameInfo &ConceptNameInfo, |
| 11805 | NamedDecl *FoundDecl, TemplateDecl *NamedConcept, |
| 11806 | const TemplateArgumentListInfo *TemplateArgs, |
| 11807 | bool DoCheckConstraintSatisfaction = true); |
| 11808 | |
| 11809 | void diagnoseMissingTemplateArguments(TemplateName Name, SourceLocation Loc); |
| 11810 | void diagnoseMissingTemplateArguments(const CXXScopeSpec &SS, |
| 11811 | bool TemplateKeyword, TemplateDecl *TD, |
| 11812 | SourceLocation Loc); |
| 11813 | |
| 11814 | ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 11815 | SourceLocation TemplateKWLoc, LookupResult &R, |
| 11816 | bool RequiresADL, |
| 11817 | const TemplateArgumentListInfo *TemplateArgs); |
| 11818 | |
| 11819 | // We actually only call this from template instantiation. |
| 11820 | ExprResult |
| 11821 | BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
| 11822 | const DeclarationNameInfo &NameInfo, |
| 11823 | const TemplateArgumentListInfo *TemplateArgs, |
| 11824 | bool IsAddressOfOperand); |
| 11825 | |
| 11826 | UnsignedOrNone getPackIndex(TemplateArgument Pack) const { |
| 11827 | return Pack.pack_size() - 1 - *ArgPackSubstIndex; |
| 11828 | } |
| 11829 | |
| 11830 | TemplateArgument |
| 11831 | getPackSubstitutedTemplateArgument(TemplateArgument Arg) const { |
| 11832 | Arg = Arg.pack_elements()[*ArgPackSubstIndex]; |
| 11833 | if (Arg.isPackExpansion()) |
| 11834 | Arg = Arg.getPackExpansionPattern(); |
| 11835 | return Arg; |
| 11836 | } |
| 11837 | |
| 11838 | ExprResult BuildSubstNonTypeTemplateParmExpr( |
| 11839 | Decl *AssociatedDecl, const NonTypeTemplateParmDecl *NTTP, |
| 11840 | SourceLocation loc, TemplateArgument Replacement, |
| 11841 | UnsignedOrNone PackIndex, bool Final); |
| 11842 | |
| 11843 | /// Form a template name from a name that is syntactically required to name a |
| 11844 | /// template, either due to use of the 'template' keyword or because a name in |
| 11845 | /// this syntactic context is assumed to name a template (C++ |
| 11846 | /// [temp.names]p2-4). |
| 11847 | /// |
| 11848 | /// This action forms a template name given the name of the template and its |
| 11849 | /// optional scope specifier. This is used when the 'template' keyword is used |
| 11850 | /// or when the parsing context unambiguously treats a following '<' as |
| 11851 | /// introducing a template argument list. Note that this may produce a |
| 11852 | /// non-dependent template name if we can perform the lookup now and identify |
| 11853 | /// the named template. |
| 11854 | /// |
| 11855 | /// For example, given "x.MetaFun::template apply", the scope specifier |
| 11856 | /// \p SS will be "MetaFun::", \p TemplateKWLoc contains the location |
| 11857 | /// of the "template" keyword, and "apply" is the \p Name. |
| 11858 | TemplateNameKind ActOnTemplateName(Scope *S, CXXScopeSpec &SS, |
| 11859 | SourceLocation TemplateKWLoc, |
| 11860 | const UnqualifiedId &Name, |
| 11861 | ParsedType ObjectType, |
| 11862 | bool EnteringContext, TemplateTy &Template, |
| 11863 | bool AllowInjectedClassName = false); |
| 11864 | |
| 11865 | DeclResult ActOnClassTemplateSpecialization( |
| 11866 | Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, |
| 11867 | SourceLocation ModulePrivateLoc, CXXScopeSpec &SS, |
| 11868 | TemplateIdAnnotation &TemplateId, const ParsedAttributesView &Attr, |
| 11869 | MultiTemplateParamsArg TemplateParameterLists, |
| 11870 | SkipBodyInfo *SkipBody = nullptr); |
| 11871 | |
| 11872 | /// Check the non-type template arguments of a class template |
| 11873 | /// partial specialization according to C++ [temp.class.spec]p9. |
| 11874 | /// |
| 11875 | /// \param TemplateNameLoc the location of the template name. |
| 11876 | /// \param PrimaryTemplate the template parameters of the primary class |
| 11877 | /// template. |
| 11878 | /// \param NumExplicit the number of explicitly-specified template arguments. |
| 11879 | /// \param TemplateArgs the template arguments of the class template |
| 11880 | /// partial specialization. |
| 11881 | /// |
| 11882 | /// \returns \c true if there was an error, \c false otherwise. |
| 11883 | bool CheckTemplatePartialSpecializationArgs(SourceLocation Loc, |
| 11884 | TemplateDecl *PrimaryTemplate, |
| 11885 | unsigned NumExplicitArgs, |
| 11886 | ArrayRef<TemplateArgument> Args); |
| 11887 | void CheckTemplatePartialSpecialization( |
| 11888 | ClassTemplatePartialSpecializationDecl *Partial); |
| 11889 | void CheckTemplatePartialSpecialization( |
| 11890 | VarTemplatePartialSpecializationDecl *Partial); |
| 11891 | |
| 11892 | Decl *ActOnTemplateDeclarator(Scope *S, |
| 11893 | MultiTemplateParamsArg TemplateParameterLists, |
| 11894 | Declarator &D); |
| 11895 | |
| 11896 | /// Diagnose cases where we have an explicit template specialization |
| 11897 | /// before/after an explicit template instantiation, producing diagnostics |
| 11898 | /// for those cases where they are required and determining whether the |
| 11899 | /// new specialization/instantiation will have any effect. |
| 11900 | /// |
| 11901 | /// \param NewLoc the location of the new explicit specialization or |
| 11902 | /// instantiation. |
| 11903 | /// |
| 11904 | /// \param NewTSK the kind of the new explicit specialization or |
| 11905 | /// instantiation. |
| 11906 | /// |
| 11907 | /// \param PrevDecl the previous declaration of the entity. |
| 11908 | /// |
| 11909 | /// \param PrevTSK the kind of the old explicit specialization or |
| 11910 | /// instantiatin. |
| 11911 | /// |
| 11912 | /// \param PrevPointOfInstantiation if valid, indicates where the previous |
| 11913 | /// declaration was instantiated (either implicitly or explicitly). |
| 11914 | /// |
| 11915 | /// \param HasNoEffect will be set to true to indicate that the new |
| 11916 | /// specialization or instantiation has no effect and should be ignored. |
| 11917 | /// |
| 11918 | /// \returns true if there was an error that should prevent the introduction |
| 11919 | /// of the new declaration into the AST, false otherwise. |
| 11920 | bool CheckSpecializationInstantiationRedecl( |
| 11921 | SourceLocation NewLoc, |
| 11922 | TemplateSpecializationKind ActOnExplicitInstantiationNewTSK, |
| 11923 | NamedDecl *PrevDecl, TemplateSpecializationKind PrevTSK, |
| 11924 | SourceLocation PrevPtOfInstantiation, bool &SuppressNew); |
| 11925 | |
| 11926 | /// Perform semantic analysis for the given dependent function |
| 11927 | /// template specialization. |
| 11928 | /// |
| 11929 | /// The only possible way to get a dependent function template specialization |
| 11930 | /// is with a friend declaration, like so: |
| 11931 | /// |
| 11932 | /// \code |
| 11933 | /// template \<class T> void foo(T); |
| 11934 | /// template \<class T> class A { |
| 11935 | /// friend void foo<>(T); |
| 11936 | /// }; |
| 11937 | /// \endcode |
| 11938 | /// |
| 11939 | /// There really isn't any useful analysis we can do here, so we |
| 11940 | /// just store the information. |
| 11941 | bool CheckDependentFunctionTemplateSpecialization( |
| 11942 | FunctionDecl *FD, const TemplateArgumentListInfo *ExplicitTemplateArgs, |
| 11943 | LookupResult &Previous); |
| 11944 | |
| 11945 | /// Perform semantic analysis for the given function template |
| 11946 | /// specialization. |
| 11947 | /// |
| 11948 | /// This routine performs all of the semantic analysis required for an |
| 11949 | /// explicit function template specialization. On successful completion, |
| 11950 | /// the function declaration \p FD will become a function template |
| 11951 | /// specialization. |
| 11952 | /// |
| 11953 | /// \param FD the function declaration, which will be updated to become a |
| 11954 | /// function template specialization. |
| 11955 | /// |
| 11956 | /// \param ExplicitTemplateArgs the explicitly-provided template arguments, |
| 11957 | /// if any. Note that this may be valid info even when 0 arguments are |
| 11958 | /// explicitly provided as in, e.g., \c void sort<>(char*, char*); |
| 11959 | /// as it anyway contains info on the angle brackets locations. |
| 11960 | /// |
| 11961 | /// \param Previous the set of declarations that may be specialized by |
| 11962 | /// this function specialization. |
| 11963 | /// |
| 11964 | /// \param QualifiedFriend whether this is a lookup for a qualified friend |
| 11965 | /// declaration with no explicit template argument list that might be |
| 11966 | /// befriending a function template specialization. |
| 11967 | bool CheckFunctionTemplateSpecialization( |
| 11968 | FunctionDecl *FD, TemplateArgumentListInfo *ExplicitTemplateArgs, |
| 11969 | LookupResult &Previous, bool QualifiedFriend = false); |
| 11970 | |
| 11971 | /// Perform semantic analysis for the given non-template member |
| 11972 | /// specialization. |
| 11973 | /// |
| 11974 | /// This routine performs all of the semantic analysis required for an |
| 11975 | /// explicit member function specialization. On successful completion, |
| 11976 | /// the function declaration \p FD will become a member function |
| 11977 | /// specialization. |
| 11978 | /// |
| 11979 | /// \param Member the member declaration, which will be updated to become a |
| 11980 | /// specialization. |
| 11981 | /// |
| 11982 | /// \param Previous the set of declarations, one of which may be specialized |
| 11983 | /// by this function specialization; the set will be modified to contain the |
| 11984 | /// redeclared member. |
| 11985 | bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); |
| 11986 | void CompleteMemberSpecialization(NamedDecl *Member, LookupResult &Previous); |
| 11987 | |
| 11988 | // Explicit instantiation of a class template specialization |
| 11989 | DeclResult ActOnExplicitInstantiation( |
| 11990 | Scope *S, SourceLocation ExternLoc, SourceLocation TemplateLoc, |
| 11991 | unsigned TagSpec, SourceLocation KWLoc, const CXXScopeSpec &SS, |
| 11992 | TemplateTy Template, SourceLocation TemplateNameLoc, |
| 11993 | SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, |
| 11994 | SourceLocation RAngleLoc, const ParsedAttributesView &Attr); |
| 11995 | |
| 11996 | // Explicit instantiation of a member class of a class template. |
| 11997 | DeclResult ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc, |
| 11998 | SourceLocation TemplateLoc, |
| 11999 | unsigned TagSpec, SourceLocation KWLoc, |
| 12000 | CXXScopeSpec &SS, IdentifierInfo *Name, |
| 12001 | SourceLocation NameLoc, |
| 12002 | const ParsedAttributesView &Attr); |
| 12003 | |
| 12004 | DeclResult ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc, |
| 12005 | SourceLocation TemplateLoc, |
| 12006 | Declarator &D); |
| 12007 | |
| 12008 | /// If the given template parameter has a default template |
| 12009 | /// argument, substitute into that default template argument and |
| 12010 | /// return the corresponding template argument. |
| 12011 | TemplateArgumentLoc SubstDefaultTemplateArgumentIfAvailable( |
| 12012 | TemplateDecl *Template, SourceLocation TemplateKWLoc, |
| 12013 | SourceLocation TemplateNameLoc, SourceLocation RAngleLoc, Decl *Param, |
| 12014 | ArrayRef<TemplateArgument> SugaredConverted, |
| 12015 | ArrayRef<TemplateArgument> CanonicalConverted, bool &HasDefaultArg); |
| 12016 | |
| 12017 | /// Returns the top most location responsible for the definition of \p N. |
| 12018 | /// If \p N is a a template specialization, this is the location |
| 12019 | /// of the top of the instantiation stack. |
| 12020 | /// Otherwise, the location of \p N is returned. |
| 12021 | SourceLocation getTopMostPointOfInstantiation(const NamedDecl *) const; |
| 12022 | |
| 12023 | /// Specifies the context in which a particular template |
| 12024 | /// argument is being checked. |
| 12025 | enum CheckTemplateArgumentKind { |
| 12026 | /// The template argument was specified in the code or was |
| 12027 | /// instantiated with some deduced template arguments. |
| 12028 | CTAK_Specified, |
| 12029 | |
| 12030 | /// The template argument was deduced via template argument |
| 12031 | /// deduction. |
| 12032 | CTAK_Deduced, |
| 12033 | |
| 12034 | /// The template argument was deduced from an array bound |
| 12035 | /// via template argument deduction. |
| 12036 | CTAK_DeducedFromArrayBound |
| 12037 | }; |
| 12038 | |
| 12039 | struct CheckTemplateArgumentInfo { |
| 12040 | explicit CheckTemplateArgumentInfo(bool PartialOrdering = false, |
| 12041 | bool MatchingTTP = false) |
| 12042 | : PartialOrdering(PartialOrdering), MatchingTTP(MatchingTTP) {} |
| 12043 | CheckTemplateArgumentInfo(const CheckTemplateArgumentInfo &) = delete; |
| 12044 | CheckTemplateArgumentInfo & |
| 12045 | operator=(const CheckTemplateArgumentInfo &) = delete; |
| 12046 | |
| 12047 | /// The checked, converted argument will be added to the |
| 12048 | /// end of these vectors. |
| 12049 | SmallVector<TemplateArgument, 4> SugaredConverted, CanonicalConverted; |
| 12050 | |
| 12051 | /// The check is being performed in the context of partial ordering. |
| 12052 | bool PartialOrdering; |
| 12053 | |
| 12054 | /// If true, assume these template arguments are |
| 12055 | /// the injected template arguments for a template template parameter. |
| 12056 | /// This will relax the requirement that all its possible uses are valid: |
| 12057 | /// TTP checking is loose, and assumes that invalid uses will be diagnosed |
| 12058 | /// during instantiation. |
| 12059 | bool MatchingTTP; |
| 12060 | |
| 12061 | /// Is set to true when, in the context of TTP matching, a pack parameter |
| 12062 | /// matches non-pack arguments. |
| 12063 | bool StrictPackMatch = false; |
| 12064 | }; |
| 12065 | |
| 12066 | /// Check that the given template argument corresponds to the given |
| 12067 | /// template parameter. |
| 12068 | /// |
| 12069 | /// \param Param The template parameter against which the argument will be |
| 12070 | /// checked. |
| 12071 | /// |
| 12072 | /// \param Arg The template argument, which may be updated due to conversions. |
| 12073 | /// |
| 12074 | /// \param Template The template in which the template argument resides. |
| 12075 | /// |
| 12076 | /// \param TemplateLoc The location of the template name for the template |
| 12077 | /// whose argument list we're matching. |
| 12078 | /// |
| 12079 | /// \param RAngleLoc The location of the right angle bracket ('>') that closes |
| 12080 | /// the template argument list. |
| 12081 | /// |
| 12082 | /// \param ArgumentPackIndex The index into the argument pack where this |
| 12083 | /// argument will be placed. Only valid if the parameter is a parameter pack. |
| 12084 | /// |
| 12085 | /// \param CTAK Describes how we arrived at this particular template argument: |
| 12086 | /// explicitly written, deduced, etc. |
| 12087 | /// |
| 12088 | /// \returns true on error, false otherwise. |
| 12089 | bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, |
| 12090 | NamedDecl *Template, SourceLocation TemplateLoc, |
| 12091 | SourceLocation RAngleLoc, |
| 12092 | unsigned ArgumentPackIndex, |
| 12093 | CheckTemplateArgumentInfo &CTAI, |
| 12094 | CheckTemplateArgumentKind CTAK); |
| 12095 | |
| 12096 | /// Check that the given template arguments can be provided to |
| 12097 | /// the given template, converting the arguments along the way. |
| 12098 | /// |
| 12099 | /// \param Template The template to which the template arguments are being |
| 12100 | /// provided. |
| 12101 | /// |
| 12102 | /// \param TemplateLoc The location of the template name in the source. |
| 12103 | /// |
| 12104 | /// \param TemplateArgs The list of template arguments. If the template is |
| 12105 | /// a template template parameter, this function may extend the set of |
| 12106 | /// template arguments to also include substituted, defaulted template |
| 12107 | /// arguments. |
| 12108 | /// |
| 12109 | /// \param PartialTemplateArgs True if the list of template arguments is |
| 12110 | /// intentionally partial, e.g., because we're checking just the initial |
| 12111 | /// set of template arguments. |
| 12112 | /// |
| 12113 | /// \param Converted Will receive the converted, canonicalized template |
| 12114 | /// arguments. |
| 12115 | /// |
| 12116 | /// \param UpdateArgsWithConversions If \c true, update \p TemplateArgs to |
| 12117 | /// contain the converted forms of the template arguments as written. |
| 12118 | /// Otherwise, \p TemplateArgs will not be modified. |
| 12119 | /// |
| 12120 | /// \param ConstraintsNotSatisfied If provided, and an error occurred, will |
| 12121 | /// receive true if the cause for the error is the associated constraints of |
| 12122 | /// the template not being satisfied by the template arguments. |
| 12123 | /// |
| 12124 | /// \param DefaultArgs any default arguments from template specialization |
| 12125 | /// deduction. |
| 12126 | /// |
| 12127 | /// \returns true if an error occurred, false otherwise. |
| 12128 | bool CheckTemplateArgumentList(TemplateDecl *Template, |
| 12129 | SourceLocation TemplateLoc, |
| 12130 | TemplateArgumentListInfo &TemplateArgs, |
| 12131 | const DefaultArguments &DefaultArgs, |
| 12132 | bool PartialTemplateArgs, |
| 12133 | CheckTemplateArgumentInfo &CTAI, |
| 12134 | bool UpdateArgsWithConversions = true, |
| 12135 | bool *ConstraintsNotSatisfied = nullptr); |
| 12136 | |
| 12137 | bool CheckTemplateArgumentList( |
| 12138 | TemplateDecl *Template, TemplateParameterList *Params, |
| 12139 | SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs, |
| 12140 | const DefaultArguments &DefaultArgs, bool PartialTemplateArgs, |
| 12141 | CheckTemplateArgumentInfo &CTAI, bool UpdateArgsWithConversions = true, |
| 12142 | bool *ConstraintsNotSatisfied = nullptr); |
| 12143 | |
| 12144 | bool CheckTemplateTypeArgument( |
| 12145 | TemplateTypeParmDecl *Param, TemplateArgumentLoc &Arg, |
| 12146 | SmallVectorImpl<TemplateArgument> &SugaredConverted, |
| 12147 | SmallVectorImpl<TemplateArgument> &CanonicalConverted); |
| 12148 | |
| 12149 | /// Check a template argument against its corresponding |
| 12150 | /// template type parameter. |
| 12151 | /// |
| 12152 | /// This routine implements the semantics of C++ [temp.arg.type]. It |
| 12153 | /// returns true if an error occurred, and false otherwise. |
| 12154 | bool CheckTemplateArgument(TypeSourceInfo *Arg); |
| 12155 | |
| 12156 | /// Check a template argument against its corresponding |
| 12157 | /// non-type template parameter. |
| 12158 | /// |
| 12159 | /// This routine implements the semantics of C++ [temp.arg.nontype]. |
| 12160 | /// If an error occurred, it returns ExprError(); otherwise, it |
| 12161 | /// returns the converted template argument. \p ParamType is the |
| 12162 | /// type of the non-type template parameter after it has been instantiated. |
| 12163 | ExprResult CheckTemplateArgument(NamedDecl *Param, |
| 12164 | QualType InstantiatedParamType, Expr *Arg, |
| 12165 | TemplateArgument &SugaredConverted, |
| 12166 | TemplateArgument &CanonicalConverted, |
| 12167 | bool StrictCheck, |
| 12168 | CheckTemplateArgumentKind CTAK); |
| 12169 | |
| 12170 | /// Check a template argument against its corresponding |
| 12171 | /// template template parameter. |
| 12172 | /// |
| 12173 | /// This routine implements the semantics of C++ [temp.arg.template]. |
| 12174 | /// It returns true if an error occurred, and false otherwise. |
| 12175 | bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param, |
| 12176 | TemplateParameterList *Params, |
| 12177 | TemplateArgumentLoc &Arg, |
| 12178 | bool PartialOrdering, |
| 12179 | bool *StrictPackMatch); |
| 12180 | |
| 12181 | bool CheckDeclCompatibleWithTemplateTemplate(TemplateDecl *Template, |
| 12182 | TemplateTemplateParmDecl *Param, |
| 12183 | const TemplateArgumentLoc &Arg); |
| 12184 | |
| 12185 | void NoteTemplateLocation(const NamedDecl &Decl, |
| 12186 | std::optional<SourceRange> ParamRange = {}); |
| 12187 | void NoteTemplateParameterLocation(const NamedDecl &Decl); |
| 12188 | |
| 12189 | /// Given a non-type template argument that refers to a |
| 12190 | /// declaration and the type of its corresponding non-type template |
| 12191 | /// parameter, produce an expression that properly refers to that |
| 12192 | /// declaration. |
| 12193 | /// FIXME: This is used in some contexts where the resulting expression |
| 12194 | /// doesn't need to live too long. It would be useful if this function |
| 12195 | /// could return a temporary expression. |
| 12196 | ExprResult BuildExpressionFromDeclTemplateArgument( |
| 12197 | const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc, |
| 12198 | NamedDecl *TemplateParam = nullptr); |
| 12199 | ExprResult |
| 12200 | BuildExpressionFromNonTypeTemplateArgument(const TemplateArgument &Arg, |
| 12201 | SourceLocation Loc); |
| 12202 | |
| 12203 | /// Enumeration describing how template parameter lists are compared |
| 12204 | /// for equality. |
| 12205 | enum TemplateParameterListEqualKind { |
| 12206 | /// We are matching the template parameter lists of two templates |
| 12207 | /// that might be redeclarations. |
| 12208 | /// |
| 12209 | /// \code |
| 12210 | /// template<typename T> struct X; |
| 12211 | /// template<typename T> struct X; |
| 12212 | /// \endcode |
| 12213 | TPL_TemplateMatch, |
| 12214 | |
| 12215 | /// We are matching the template parameter lists of two template |
| 12216 | /// template parameters as part of matching the template parameter lists |
| 12217 | /// of two templates that might be redeclarations. |
| 12218 | /// |
| 12219 | /// \code |
| 12220 | /// template<template<int I> class TT> struct X; |
| 12221 | /// template<template<int Value> class Other> struct X; |
| 12222 | /// \endcode |
| 12223 | TPL_TemplateTemplateParmMatch, |
| 12224 | |
| 12225 | /// We are determining whether the template-parameters are equivalent |
| 12226 | /// according to C++ [temp.over.link]/6. This comparison does not consider |
| 12227 | /// constraints. |
| 12228 | /// |
| 12229 | /// \code |
| 12230 | /// template<C1 T> void f(T); |
| 12231 | /// template<C2 T> void f(T); |
| 12232 | /// \endcode |
| 12233 | TPL_TemplateParamsEquivalent, |
| 12234 | }; |
| 12235 | |
| 12236 | // A struct to represent the 'new' declaration, which is either itself just |
| 12237 | // the named decl, or the important information we need about it in order to |
| 12238 | // do constraint comparisons. |
| 12239 | class TemplateCompareNewDeclInfo { |
| 12240 | const NamedDecl *ND = nullptr; |
| 12241 | const DeclContext *DC = nullptr; |
| 12242 | const DeclContext *LexicalDC = nullptr; |
| 12243 | SourceLocation Loc; |
| 12244 | |
| 12245 | public: |
| 12246 | TemplateCompareNewDeclInfo(const NamedDecl *ND) : ND(ND) {} |
| 12247 | TemplateCompareNewDeclInfo(const DeclContext *DeclCtx, |
| 12248 | const DeclContext *LexicalDeclCtx, |
| 12249 | SourceLocation Loc) |
| 12250 | |
| 12251 | : DC(DeclCtx), LexicalDC(LexicalDeclCtx), Loc(Loc) { |
| 12252 | assert(DC && LexicalDC && |
| 12253 | "Constructor only for cases where we have the information to put " |
| 12254 | "in here" ); |
| 12255 | } |
| 12256 | |
| 12257 | // If this was constructed with no information, we cannot do substitution |
| 12258 | // for constraint comparison, so make sure we can check that. |
| 12259 | bool isInvalid() const { return !ND && !DC; } |
| 12260 | |
| 12261 | const NamedDecl *getDecl() const { return ND; } |
| 12262 | |
| 12263 | bool ContainsDecl(const NamedDecl *ND) const { return this->ND == ND; } |
| 12264 | |
| 12265 | const DeclContext *getLexicalDeclContext() const { |
| 12266 | return ND ? ND->getLexicalDeclContext() : LexicalDC; |
| 12267 | } |
| 12268 | |
| 12269 | const DeclContext *getDeclContext() const { |
| 12270 | return ND ? ND->getDeclContext() : DC; |
| 12271 | } |
| 12272 | |
| 12273 | SourceLocation getLocation() const { return ND ? ND->getLocation() : Loc; } |
| 12274 | }; |
| 12275 | |
| 12276 | /// Determine whether the given template parameter lists are |
| 12277 | /// equivalent. |
| 12278 | /// |
| 12279 | /// \param New The new template parameter list, typically written in the |
| 12280 | /// source code as part of a new template declaration. |
| 12281 | /// |
| 12282 | /// \param Old The old template parameter list, typically found via |
| 12283 | /// name lookup of the template declared with this template parameter |
| 12284 | /// list. |
| 12285 | /// |
| 12286 | /// \param Complain If true, this routine will produce a diagnostic if |
| 12287 | /// the template parameter lists are not equivalent. |
| 12288 | /// |
| 12289 | /// \param Kind describes how we are to match the template parameter lists. |
| 12290 | /// |
| 12291 | /// \param TemplateArgLoc If this source location is valid, then we |
| 12292 | /// are actually checking the template parameter list of a template |
| 12293 | /// argument (New) against the template parameter list of its |
| 12294 | /// corresponding template template parameter (Old). We produce |
| 12295 | /// slightly different diagnostics in this scenario. |
| 12296 | /// |
| 12297 | /// \returns True if the template parameter lists are equal, false |
| 12298 | /// otherwise. |
| 12299 | bool TemplateParameterListsAreEqual( |
| 12300 | const TemplateCompareNewDeclInfo &NewInstFrom, TemplateParameterList *New, |
| 12301 | const NamedDecl *OldInstFrom, TemplateParameterList *Old, bool Complain, |
| 12302 | TemplateParameterListEqualKind Kind, |
| 12303 | SourceLocation TemplateArgLoc = SourceLocation()); |
| 12304 | |
| 12305 | bool TemplateParameterListsAreEqual( |
| 12306 | TemplateParameterList *New, TemplateParameterList *Old, bool Complain, |
| 12307 | TemplateParameterListEqualKind Kind, |
| 12308 | SourceLocation TemplateArgLoc = SourceLocation()) { |
| 12309 | return TemplateParameterListsAreEqual(NewInstFrom: nullptr, New, OldInstFrom: nullptr, Old, Complain, |
| 12310 | Kind, TemplateArgLoc); |
| 12311 | } |
| 12312 | |
| 12313 | /// Check whether a template can be declared within this scope. |
| 12314 | /// |
| 12315 | /// If the template declaration is valid in this scope, returns |
| 12316 | /// false. Otherwise, issues a diagnostic and returns true. |
| 12317 | bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); |
| 12318 | |
| 12319 | /// Called when the parser has parsed a C++ typename |
| 12320 | /// specifier, e.g., "typename T::type". |
| 12321 | /// |
| 12322 | /// \param S The scope in which this typename type occurs. |
| 12323 | /// \param TypenameLoc the location of the 'typename' keyword |
| 12324 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
| 12325 | /// \param II the identifier we're retrieving (e.g., 'type' in the example). |
| 12326 | /// \param IdLoc the location of the identifier. |
| 12327 | /// \param IsImplicitTypename context where T::type refers to a type. |
| 12328 | TypeResult ActOnTypenameType( |
| 12329 | Scope *S, SourceLocation TypenameLoc, const CXXScopeSpec &SS, |
| 12330 | const IdentifierInfo &II, SourceLocation IdLoc, |
| 12331 | ImplicitTypenameContext IsImplicitTypename = ImplicitTypenameContext::No); |
| 12332 | |
| 12333 | /// Called when the parser has parsed a C++ typename |
| 12334 | /// specifier that ends in a template-id, e.g., |
| 12335 | /// "typename MetaFun::template apply<T1, T2>". |
| 12336 | /// |
| 12337 | /// \param S The scope in which this typename type occurs. |
| 12338 | /// \param TypenameLoc the location of the 'typename' keyword |
| 12339 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
| 12340 | /// \param TemplateLoc the location of the 'template' keyword, if any. |
| 12341 | /// \param TemplateName The template name. |
| 12342 | /// \param TemplateII The identifier used to name the template. |
| 12343 | /// \param TemplateIILoc The location of the template name. |
| 12344 | /// \param LAngleLoc The location of the opening angle bracket ('<'). |
| 12345 | /// \param TemplateArgs The template arguments. |
| 12346 | /// \param RAngleLoc The location of the closing angle bracket ('>'). |
| 12347 | TypeResult |
| 12348 | ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, |
| 12349 | const CXXScopeSpec &SS, SourceLocation TemplateLoc, |
| 12350 | TemplateTy TemplateName, const IdentifierInfo *TemplateII, |
| 12351 | SourceLocation TemplateIILoc, SourceLocation LAngleLoc, |
| 12352 | ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc); |
| 12353 | |
| 12354 | QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, |
| 12355 | SourceLocation KeywordLoc, |
| 12356 | NestedNameSpecifierLoc QualifierLoc, |
| 12357 | const IdentifierInfo &II, SourceLocation IILoc, |
| 12358 | TypeSourceInfo **TSI, bool DeducedTSTContext); |
| 12359 | |
| 12360 | QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, |
| 12361 | SourceLocation KeywordLoc, |
| 12362 | NestedNameSpecifierLoc QualifierLoc, |
| 12363 | const IdentifierInfo &II, SourceLocation IILoc, |
| 12364 | bool DeducedTSTContext = true); |
| 12365 | |
| 12366 | /// Rebuilds a type within the context of the current instantiation. |
| 12367 | /// |
| 12368 | /// The type \p T is part of the type of an out-of-line member definition of |
| 12369 | /// a class template (or class template partial specialization) that was |
| 12370 | /// parsed and constructed before we entered the scope of the class template |
| 12371 | /// (or partial specialization thereof). This routine will rebuild that type |
| 12372 | /// now that we have entered the declarator's scope, which may produce |
| 12373 | /// different canonical types, e.g., |
| 12374 | /// |
| 12375 | /// \code |
| 12376 | /// template<typename T> |
| 12377 | /// struct X { |
| 12378 | /// typedef T* pointer; |
| 12379 | /// pointer data(); |
| 12380 | /// }; |
| 12381 | /// |
| 12382 | /// template<typename T> |
| 12383 | /// typename X<T>::pointer X<T>::data() { ... } |
| 12384 | /// \endcode |
| 12385 | /// |
| 12386 | /// Here, the type "typename X<T>::pointer" will be created as a |
| 12387 | /// DependentNameType, since we do not know that we can look into X<T> when we |
| 12388 | /// parsed the type. This function will rebuild the type, performing the |
| 12389 | /// lookup of "pointer" in X<T> and returning an ElaboratedType whose |
| 12390 | /// canonical type is the same as the canonical type of T*, allowing the |
| 12391 | /// return types of the out-of-line definition and the declaration to match. |
| 12392 | TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, |
| 12393 | SourceLocation Loc, |
| 12394 | DeclarationName Name); |
| 12395 | bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); |
| 12396 | |
| 12397 | ExprResult RebuildExprInCurrentInstantiation(Expr *E); |
| 12398 | |
| 12399 | /// Rebuild the template parameters now that we know we're in a current |
| 12400 | /// instantiation. |
| 12401 | bool |
| 12402 | RebuildTemplateParamsInCurrentInstantiation(TemplateParameterList *Params); |
| 12403 | |
| 12404 | /// Produces a formatted string that describes the binding of |
| 12405 | /// template parameters to template arguments. |
| 12406 | std::string |
| 12407 | getTemplateArgumentBindingsText(const TemplateParameterList *Params, |
| 12408 | const TemplateArgumentList &Args); |
| 12409 | |
| 12410 | std::string |
| 12411 | getTemplateArgumentBindingsText(const TemplateParameterList *Params, |
| 12412 | const TemplateArgument *Args, |
| 12413 | unsigned NumArgs); |
| 12414 | |
| 12415 | void diagnoseExprIntendedAsTemplateName(Scope *S, ExprResult TemplateName, |
| 12416 | SourceLocation Less, |
| 12417 | SourceLocation Greater); |
| 12418 | |
| 12419 | /// ActOnDependentIdExpression - Handle a dependent id-expression that |
| 12420 | /// was just parsed. This is only possible with an explicit scope |
| 12421 | /// specifier naming a dependent type. |
| 12422 | ExprResult ActOnDependentIdExpression( |
| 12423 | const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
| 12424 | const DeclarationNameInfo &NameInfo, bool isAddressOfOperand, |
| 12425 | const TemplateArgumentListInfo *TemplateArgs); |
| 12426 | |
| 12427 | ExprResult |
| 12428 | BuildDependentDeclRefExpr(const CXXScopeSpec &SS, |
| 12429 | SourceLocation TemplateKWLoc, |
| 12430 | const DeclarationNameInfo &NameInfo, |
| 12431 | const TemplateArgumentListInfo *TemplateArgs); |
| 12432 | |
| 12433 | // Calculates whether the expression Constraint depends on an enclosing |
| 12434 | // template, for the purposes of [temp.friend] p9. |
| 12435 | // TemplateDepth is the 'depth' of the friend function, which is used to |
| 12436 | // compare whether a declaration reference is referring to a containing |
| 12437 | // template, or just the current friend function. A 'lower' TemplateDepth in |
| 12438 | // the AST refers to a 'containing' template. As the constraint is |
| 12439 | // uninstantiated, this is relative to the 'top' of the TU. |
| 12440 | bool |
| 12441 | ConstraintExpressionDependsOnEnclosingTemplate(const FunctionDecl *Friend, |
| 12442 | unsigned TemplateDepth, |
| 12443 | const Expr *Constraint); |
| 12444 | |
| 12445 | /// Find the failed Boolean condition within a given Boolean |
| 12446 | /// constant expression, and describe it with a string. |
| 12447 | std::pair<Expr *, std::string> findFailedBooleanCondition(Expr *Cond); |
| 12448 | |
| 12449 | void CheckDeductionGuideTemplate(FunctionTemplateDecl *TD); |
| 12450 | |
| 12451 | ConceptDecl *ActOnStartConceptDefinition( |
| 12452 | Scope *S, MultiTemplateParamsArg TemplateParameterLists, |
| 12453 | const IdentifierInfo *Name, SourceLocation NameLoc); |
| 12454 | |
| 12455 | ConceptDecl *ActOnFinishConceptDefinition(Scope *S, ConceptDecl *C, |
| 12456 | Expr *ConstraintExpr, |
| 12457 | const ParsedAttributesView &Attrs); |
| 12458 | |
| 12459 | void CheckConceptRedefinition(ConceptDecl *NewDecl, LookupResult &Previous, |
| 12460 | bool &AddToScope); |
| 12461 | bool CheckConceptUseInDefinition(NamedDecl *Concept, SourceLocation Loc); |
| 12462 | |
| 12463 | TypeResult ActOnDependentTag(Scope *S, unsigned TagSpec, TagUseKind TUK, |
| 12464 | const CXXScopeSpec &SS, |
| 12465 | const IdentifierInfo *Name, |
| 12466 | SourceLocation TagLoc, SourceLocation NameLoc); |
| 12467 | |
| 12468 | void MarkAsLateParsedTemplate(FunctionDecl *FD, Decl *FnD, |
| 12469 | CachedTokens &Toks); |
| 12470 | void UnmarkAsLateParsedTemplate(FunctionDecl *FD); |
| 12471 | bool IsInsideALocalClassWithinATemplateFunction(); |
| 12472 | |
| 12473 | /// We've found a use of a templated declaration that would trigger an |
| 12474 | /// implicit instantiation. Check that any relevant explicit specializations |
| 12475 | /// and partial specializations are visible/reachable, and diagnose if not. |
| 12476 | void checkSpecializationVisibility(SourceLocation Loc, NamedDecl *Spec); |
| 12477 | void checkSpecializationReachability(SourceLocation Loc, NamedDecl *Spec); |
| 12478 | |
| 12479 | ///@} |
| 12480 | |
| 12481 | // |
| 12482 | // |
| 12483 | // ------------------------------------------------------------------------- |
| 12484 | // |
| 12485 | // |
| 12486 | |
| 12487 | /// \name C++ Template Argument Deduction |
| 12488 | /// Implementations are in SemaTemplateDeduction.cpp |
| 12489 | ///@{ |
| 12490 | |
| 12491 | public: |
| 12492 | class SFINAETrap; |
| 12493 | |
| 12494 | struct SFINAEContextBase { |
| 12495 | SFINAEContextBase(Sema &S, SFINAETrap *Cur) |
| 12496 | : S(S), Prev(std::exchange(obj&: S.CurrentSFINAEContext, new_val&: Cur)) {} |
| 12497 | |
| 12498 | protected: |
| 12499 | Sema &S; |
| 12500 | ~SFINAEContextBase() { S.CurrentSFINAEContext = Prev; } |
| 12501 | SFINAEContextBase(const SFINAEContextBase &) = delete; |
| 12502 | SFINAEContextBase &operator=(const SFINAEContextBase &) = delete; |
| 12503 | |
| 12504 | private: |
| 12505 | SFINAETrap *Prev; |
| 12506 | }; |
| 12507 | |
| 12508 | struct NonSFINAEContext : SFINAEContextBase { |
| 12509 | NonSFINAEContext(Sema &S) : SFINAEContextBase(S, nullptr) {} |
| 12510 | }; |
| 12511 | |
| 12512 | /// RAII class used to determine whether SFINAE has |
| 12513 | /// trapped any errors that occur during template argument |
| 12514 | /// deduction. |
| 12515 | class SFINAETrap : SFINAEContextBase { |
| 12516 | bool HasErrorOcurred = false; |
| 12517 | bool WithAccessChecking = false; |
| 12518 | bool PrevLastDiagnosticIgnored = |
| 12519 | S.getDiagnostics().isLastDiagnosticIgnored(); |
| 12520 | sema::TemplateDeductionInfo *DeductionInfo = nullptr; |
| 12521 | |
| 12522 | SFINAETrap(Sema &S, sema::TemplateDeductionInfo *Info, |
| 12523 | bool WithAccessChecking) |
| 12524 | : SFINAEContextBase(S, this), WithAccessChecking(WithAccessChecking), |
| 12525 | DeductionInfo(Info) {} |
| 12526 | |
| 12527 | public: |
| 12528 | /// \param WithAccessChecking If true, discard all diagnostics (from the |
| 12529 | /// immediate context) instead of adding them to the currently active |
| 12530 | /// \ref TemplateDeductionInfo. |
| 12531 | explicit SFINAETrap(Sema &S, bool WithAccessChecking = false) |
| 12532 | : SFINAETrap(S, /*Info=*/nullptr, WithAccessChecking) {} |
| 12533 | |
| 12534 | SFINAETrap(Sema &S, sema::TemplateDeductionInfo &Info) |
| 12535 | : SFINAETrap(S, &Info, /*WithAccessChecking=*/false) {} |
| 12536 | |
| 12537 | ~SFINAETrap() { |
| 12538 | S.getDiagnostics().setLastDiagnosticIgnored(PrevLastDiagnosticIgnored); |
| 12539 | } |
| 12540 | |
| 12541 | SFINAETrap(const SFINAETrap &) = delete; |
| 12542 | SFINAETrap &operator=(const SFINAETrap &) = delete; |
| 12543 | |
| 12544 | sema::TemplateDeductionInfo *getDeductionInfo() const { |
| 12545 | return DeductionInfo; |
| 12546 | } |
| 12547 | |
| 12548 | /// Determine whether any SFINAE errors have been trapped. |
| 12549 | bool hasErrorOccurred() const { return HasErrorOcurred; } |
| 12550 | void setErrorOccurred() { HasErrorOcurred = true; } |
| 12551 | |
| 12552 | bool withAccessChecking() const { return WithAccessChecking; } |
| 12553 | }; |
| 12554 | |
| 12555 | /// RAII class used to indicate that we are performing provisional |
| 12556 | /// semantic analysis to determine the validity of a construct, so |
| 12557 | /// typo-correction and diagnostics in the immediate context (not within |
| 12558 | /// implicitly-instantiated templates) should be suppressed. |
| 12559 | class TentativeAnalysisScope { |
| 12560 | Sema &SemaRef; |
| 12561 | // FIXME: Using a SFINAETrap for this is a hack. |
| 12562 | SFINAETrap Trap; |
| 12563 | bool PrevDisableTypoCorrection; |
| 12564 | |
| 12565 | public: |
| 12566 | explicit TentativeAnalysisScope(Sema &SemaRef) |
| 12567 | : SemaRef(SemaRef), Trap(SemaRef, /*ForValidityCheck=*/true), |
| 12568 | PrevDisableTypoCorrection(SemaRef.DisableTypoCorrection) { |
| 12569 | SemaRef.DisableTypoCorrection = true; |
| 12570 | } |
| 12571 | ~TentativeAnalysisScope() { |
| 12572 | SemaRef.DisableTypoCorrection = PrevDisableTypoCorrection; |
| 12573 | } |
| 12574 | |
| 12575 | TentativeAnalysisScope(const TentativeAnalysisScope &) = delete; |
| 12576 | TentativeAnalysisScope &operator=(const TentativeAnalysisScope &) = delete; |
| 12577 | }; |
| 12578 | |
| 12579 | /// For each declaration that involved template argument deduction, the |
| 12580 | /// set of diagnostics that were suppressed during that template argument |
| 12581 | /// deduction. |
| 12582 | /// |
| 12583 | /// FIXME: Serialize this structure to the AST file. |
| 12584 | typedef llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1>> |
| 12585 | SuppressedDiagnosticsMap; |
| 12586 | SuppressedDiagnosticsMap SuppressedDiagnostics; |
| 12587 | |
| 12588 | /// Compare types for equality with respect to possibly compatible |
| 12589 | /// function types (noreturn adjustment, implicit calling conventions). If any |
| 12590 | /// of parameter and argument is not a function, just perform type comparison. |
| 12591 | /// |
| 12592 | /// \param P the template parameter type. |
| 12593 | /// |
| 12594 | /// \param A the argument type. |
| 12595 | bool isSameOrCompatibleFunctionType(QualType Param, QualType Arg); |
| 12596 | |
| 12597 | /// Allocate a TemplateArgumentLoc where all locations have |
| 12598 | /// been initialized to the given location. |
| 12599 | /// |
| 12600 | /// \param Arg The template argument we are producing template argument |
| 12601 | /// location information for. |
| 12602 | /// |
| 12603 | /// \param NTTPType For a declaration template argument, the type of |
| 12604 | /// the non-type template parameter that corresponds to this template |
| 12605 | /// argument. Can be null if no type sugar is available to add to the |
| 12606 | /// type from the template argument. |
| 12607 | /// |
| 12608 | /// \param Loc The source location to use for the resulting template |
| 12609 | /// argument. |
| 12610 | TemplateArgumentLoc |
| 12611 | getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, QualType NTTPType, |
| 12612 | SourceLocation Loc, |
| 12613 | NamedDecl *TemplateParam = nullptr); |
| 12614 | |
| 12615 | /// Get a template argument mapping the given template parameter to itself, |
| 12616 | /// e.g. for X in \c template<int X>, this would return an expression template |
| 12617 | /// argument referencing X. |
| 12618 | TemplateArgumentLoc getIdentityTemplateArgumentLoc(NamedDecl *Param, |
| 12619 | SourceLocation Location); |
| 12620 | |
| 12621 | /// Adjust the type \p ArgFunctionType to match the calling convention, |
| 12622 | /// noreturn, and optionally the exception specification of \p FunctionType. |
| 12623 | /// Deduction often wants to ignore these properties when matching function |
| 12624 | /// types. |
| 12625 | QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType FunctionType, |
| 12626 | bool AdjustExceptionSpec = false); |
| 12627 | |
| 12628 | TemplateDeductionResult |
| 12629 | DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, |
| 12630 | ArrayRef<TemplateArgument> TemplateArgs, |
| 12631 | sema::TemplateDeductionInfo &Info); |
| 12632 | |
| 12633 | TemplateDeductionResult |
| 12634 | DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial, |
| 12635 | ArrayRef<TemplateArgument> TemplateArgs, |
| 12636 | sema::TemplateDeductionInfo &Info); |
| 12637 | |
| 12638 | /// Deduce the template arguments of the given template from \p FromType. |
| 12639 | /// Used to implement the IsDeducible constraint for alias CTAD per C++ |
| 12640 | /// [over.match.class.deduct]p4. |
| 12641 | /// |
| 12642 | /// It only supports class or type alias templates. |
| 12643 | TemplateDeductionResult |
| 12644 | DeduceTemplateArgumentsFromType(TemplateDecl *TD, QualType FromType, |
| 12645 | sema::TemplateDeductionInfo &Info); |
| 12646 | |
| 12647 | TemplateDeductionResult DeduceTemplateArguments( |
| 12648 | TemplateParameterList *TemplateParams, ArrayRef<TemplateArgument> Ps, |
| 12649 | ArrayRef<TemplateArgument> As, sema::TemplateDeductionInfo &Info, |
| 12650 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
| 12651 | bool NumberOfArgumentsMustMatch); |
| 12652 | |
| 12653 | /// Substitute the explicitly-provided template arguments into the |
| 12654 | /// given function template according to C++ [temp.arg.explicit]. |
| 12655 | /// |
| 12656 | /// \param FunctionTemplate the function template into which the explicit |
| 12657 | /// template arguments will be substituted. |
| 12658 | /// |
| 12659 | /// \param ExplicitTemplateArgs the explicitly-specified template |
| 12660 | /// arguments. |
| 12661 | /// |
| 12662 | /// \param Deduced the deduced template arguments, which will be populated |
| 12663 | /// with the converted and checked explicit template arguments. |
| 12664 | /// |
| 12665 | /// \param ParamTypes will be populated with the instantiated function |
| 12666 | /// parameters. |
| 12667 | /// |
| 12668 | /// \param FunctionType if non-NULL, the result type of the function template |
| 12669 | /// will also be instantiated and the pointed-to value will be updated with |
| 12670 | /// the instantiated function type. |
| 12671 | /// |
| 12672 | /// \param Info if substitution fails for any reason, this object will be |
| 12673 | /// populated with more information about the failure. |
| 12674 | /// |
| 12675 | /// \returns TemplateDeductionResult::Success if substitution was successful, |
| 12676 | /// or some failure condition. |
| 12677 | TemplateDeductionResult SubstituteExplicitTemplateArguments( |
| 12678 | FunctionTemplateDecl *FunctionTemplate, |
| 12679 | TemplateArgumentListInfo &ExplicitTemplateArgs, |
| 12680 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
| 12681 | SmallVectorImpl<QualType> &ParamTypes, QualType *FunctionType, |
| 12682 | sema::TemplateDeductionInfo &Info); |
| 12683 | |
| 12684 | /// brief A function argument from which we performed template argument |
| 12685 | // deduction for a call. |
| 12686 | struct OriginalCallArg { |
| 12687 | OriginalCallArg(QualType OriginalParamType, bool DecomposedParam, |
| 12688 | unsigned ArgIdx, QualType OriginalArgType) |
| 12689 | : OriginalParamType(OriginalParamType), |
| 12690 | DecomposedParam(DecomposedParam), ArgIdx(ArgIdx), |
| 12691 | OriginalArgType(OriginalArgType) {} |
| 12692 | |
| 12693 | QualType OriginalParamType; |
| 12694 | bool DecomposedParam; |
| 12695 | unsigned ArgIdx; |
| 12696 | QualType OriginalArgType; |
| 12697 | }; |
| 12698 | |
| 12699 | /// Finish template argument deduction for a function template, |
| 12700 | /// checking the deduced template arguments for completeness and forming |
| 12701 | /// the function template specialization. |
| 12702 | /// |
| 12703 | /// \param OriginalCallArgs If non-NULL, the original call arguments against |
| 12704 | /// which the deduced argument types should be compared. |
| 12705 | /// \param CheckNonDependent Callback before substituting into the declaration |
| 12706 | /// with the deduced template arguments. |
| 12707 | /// \param OnlyInitializeNonUserDefinedConversions is used as a workaround for |
| 12708 | /// some breakages introduced by CWG2369, where non-user-defined conversions |
| 12709 | /// are checked first before the constraints. |
| 12710 | TemplateDeductionResult FinishTemplateArgumentDeduction( |
| 12711 | FunctionTemplateDecl *FunctionTemplate, |
| 12712 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
| 12713 | unsigned NumExplicitlySpecified, FunctionDecl *&Specialization, |
| 12714 | sema::TemplateDeductionInfo &Info, |
| 12715 | SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs, |
| 12716 | bool PartialOverloading, bool PartialOrdering, |
| 12717 | bool ForOverloadSetAddressResolution, |
| 12718 | llvm::function_ref<bool(bool)> CheckNonDependent = |
| 12719 | [](bool /*OnlyInitializeNonUserDefinedConversions*/) { |
| 12720 | return false; |
| 12721 | }); |
| 12722 | |
| 12723 | /// Perform template argument deduction from a function call |
| 12724 | /// (C++ [temp.deduct.call]). |
| 12725 | /// |
| 12726 | /// \param FunctionTemplate the function template for which we are performing |
| 12727 | /// template argument deduction. |
| 12728 | /// |
| 12729 | /// \param ExplicitTemplateArgs the explicit template arguments provided |
| 12730 | /// for this call. |
| 12731 | /// |
| 12732 | /// \param Args the function call arguments |
| 12733 | /// |
| 12734 | /// \param Specialization if template argument deduction was successful, |
| 12735 | /// this will be set to the function template specialization produced by |
| 12736 | /// template argument deduction. |
| 12737 | /// |
| 12738 | /// \param Info the argument will be updated to provide additional information |
| 12739 | /// about template argument deduction. |
| 12740 | /// |
| 12741 | /// \param CheckNonDependent A callback to invoke to check conversions for |
| 12742 | /// non-dependent parameters, between deduction and substitution, per DR1391. |
| 12743 | /// If this returns true, substitution will be skipped and we return |
| 12744 | /// TemplateDeductionResult::NonDependentConversionFailure. The callback is |
| 12745 | /// passed the parameter types (after substituting explicit template |
| 12746 | /// arguments). |
| 12747 | /// |
| 12748 | /// \returns the result of template argument deduction. |
| 12749 | TemplateDeductionResult DeduceTemplateArguments( |
| 12750 | FunctionTemplateDecl *FunctionTemplate, |
| 12751 | TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, |
| 12752 | FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info, |
| 12753 | bool PartialOverloading, bool AggregateDeductionCandidate, |
| 12754 | bool PartialOrdering, QualType ObjectType, |
| 12755 | Expr::Classification ObjectClassification, |
| 12756 | bool ForOverloadSetAddressResolution, |
| 12757 | llvm::function_ref<bool(ArrayRef<QualType>, bool)> CheckNonDependent); |
| 12758 | |
| 12759 | /// Deduce template arguments when taking the address of a function |
| 12760 | /// template (C++ [temp.deduct.funcaddr]) or matching a specialization to |
| 12761 | /// a template. |
| 12762 | /// |
| 12763 | /// \param FunctionTemplate the function template for which we are performing |
| 12764 | /// template argument deduction. |
| 12765 | /// |
| 12766 | /// \param ExplicitTemplateArgs the explicitly-specified template |
| 12767 | /// arguments. |
| 12768 | /// |
| 12769 | /// \param ArgFunctionType the function type that will be used as the |
| 12770 | /// "argument" type (A) when performing template argument deduction from the |
| 12771 | /// function template's function type. This type may be NULL, if there is no |
| 12772 | /// argument type to compare against, in C++0x [temp.arg.explicit]p3. |
| 12773 | /// |
| 12774 | /// \param Specialization if template argument deduction was successful, |
| 12775 | /// this will be set to the function template specialization produced by |
| 12776 | /// template argument deduction. |
| 12777 | /// |
| 12778 | /// \param Info the argument will be updated to provide additional information |
| 12779 | /// about template argument deduction. |
| 12780 | /// |
| 12781 | /// \param IsAddressOfFunction If \c true, we are deducing as part of taking |
| 12782 | /// the address of a function template per [temp.deduct.funcaddr] and |
| 12783 | /// [over.over]. If \c false, we are looking up a function template |
| 12784 | /// specialization based on its signature, per [temp.deduct.decl]. |
| 12785 | /// |
| 12786 | /// \returns the result of template argument deduction. |
| 12787 | TemplateDeductionResult DeduceTemplateArguments( |
| 12788 | FunctionTemplateDecl *FunctionTemplate, |
| 12789 | TemplateArgumentListInfo *ExplicitTemplateArgs, QualType ArgFunctionType, |
| 12790 | FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info, |
| 12791 | bool IsAddressOfFunction = false); |
| 12792 | |
| 12793 | /// Deduce template arguments for a templated conversion |
| 12794 | /// function (C++ [temp.deduct.conv]) and, if successful, produce a |
| 12795 | /// conversion function template specialization. |
| 12796 | TemplateDeductionResult DeduceTemplateArguments( |
| 12797 | FunctionTemplateDecl *FunctionTemplate, QualType ObjectType, |
| 12798 | Expr::Classification ObjectClassification, QualType ToType, |
| 12799 | CXXConversionDecl *&Specialization, sema::TemplateDeductionInfo &Info); |
| 12800 | |
| 12801 | /// Deduce template arguments for a function template when there is |
| 12802 | /// nothing to deduce against (C++0x [temp.arg.explicit]p3). |
| 12803 | /// |
| 12804 | /// \param FunctionTemplate the function template for which we are performing |
| 12805 | /// template argument deduction. |
| 12806 | /// |
| 12807 | /// \param ExplicitTemplateArgs the explicitly-specified template |
| 12808 | /// arguments. |
| 12809 | /// |
| 12810 | /// \param Specialization if template argument deduction was successful, |
| 12811 | /// this will be set to the function template specialization produced by |
| 12812 | /// template argument deduction. |
| 12813 | /// |
| 12814 | /// \param Info the argument will be updated to provide additional information |
| 12815 | /// about template argument deduction. |
| 12816 | /// |
| 12817 | /// \param IsAddressOfFunction If \c true, we are deducing as part of taking |
| 12818 | /// the address of a function template in a context where we do not have a |
| 12819 | /// target type, per [over.over]. If \c false, we are looking up a function |
| 12820 | /// template specialization based on its signature, which only happens when |
| 12821 | /// deducing a function parameter type from an argument that is a template-id |
| 12822 | /// naming a function template specialization. |
| 12823 | /// |
| 12824 | /// \returns the result of template argument deduction. |
| 12825 | TemplateDeductionResult |
| 12826 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
| 12827 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
| 12828 | FunctionDecl *&Specialization, |
| 12829 | sema::TemplateDeductionInfo &Info, |
| 12830 | bool IsAddressOfFunction = false); |
| 12831 | |
| 12832 | /// Substitute Replacement for \p auto in \p TypeWithAuto |
| 12833 | QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement); |
| 12834 | /// Substitute Replacement for auto in TypeWithAuto |
| 12835 | TypeSourceInfo *SubstAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, |
| 12836 | QualType Replacement); |
| 12837 | |
| 12838 | // Substitute auto in TypeWithAuto for a Dependent auto type |
| 12839 | QualType SubstAutoTypeDependent(QualType TypeWithAuto); |
| 12840 | |
| 12841 | // Substitute auto in TypeWithAuto for a Dependent auto type |
| 12842 | TypeSourceInfo * |
| 12843 | SubstAutoTypeSourceInfoDependent(TypeSourceInfo *TypeWithAuto); |
| 12844 | |
| 12845 | /// Completely replace the \c auto in \p TypeWithAuto by |
| 12846 | /// \p Replacement. This does not retain any \c auto type sugar. |
| 12847 | QualType ReplaceAutoType(QualType TypeWithAuto, QualType Replacement); |
| 12848 | TypeSourceInfo *ReplaceAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, |
| 12849 | QualType Replacement); |
| 12850 | |
| 12851 | /// Deduce the type for an auto type-specifier (C++11 [dcl.spec.auto]p6) |
| 12852 | /// |
| 12853 | /// Note that this is done even if the initializer is dependent. (This is |
| 12854 | /// necessary to support partial ordering of templates using 'auto'.) |
| 12855 | /// A dependent type will be produced when deducing from a dependent type. |
| 12856 | /// |
| 12857 | /// \param Type the type pattern using the auto type-specifier. |
| 12858 | /// \param Init the initializer for the variable whose type is to be deduced. |
| 12859 | /// \param Result if type deduction was successful, this will be set to the |
| 12860 | /// deduced type. |
| 12861 | /// \param Info the argument will be updated to provide additional information |
| 12862 | /// about template argument deduction. |
| 12863 | /// \param DependentDeduction Set if we should permit deduction in |
| 12864 | /// dependent cases. This is necessary for template partial ordering |
| 12865 | /// with 'auto' template parameters. The template parameter depth to be |
| 12866 | /// used should be specified in the 'Info' parameter. |
| 12867 | /// \param IgnoreConstraints Set if we should not fail if the deduced type |
| 12868 | /// does not satisfy the type-constraint in the auto |
| 12869 | /// type. |
| 12870 | TemplateDeductionResult |
| 12871 | DeduceAutoType(TypeLoc AutoTypeLoc, Expr *Initializer, QualType &Result, |
| 12872 | sema::TemplateDeductionInfo &Info, |
| 12873 | bool DependentDeduction = false, |
| 12874 | bool IgnoreConstraints = false, |
| 12875 | TemplateSpecCandidateSet *FailedTSC = nullptr); |
| 12876 | void DiagnoseAutoDeductionFailure(const VarDecl *VDecl, const Expr *Init); |
| 12877 | bool DeduceReturnType(FunctionDecl *FD, SourceLocation Loc, |
| 12878 | bool Diagnose = true); |
| 12879 | |
| 12880 | bool CheckIfFunctionSpecializationIsImmediate(FunctionDecl *FD, |
| 12881 | SourceLocation Loc); |
| 12882 | |
| 12883 | /// Returns the more specialized class template partial specialization |
| 12884 | /// according to the rules of partial ordering of class template partial |
| 12885 | /// specializations (C++ [temp.class.order]). |
| 12886 | /// |
| 12887 | /// \param PS1 the first class template partial specialization |
| 12888 | /// |
| 12889 | /// \param PS2 the second class template partial specialization |
| 12890 | /// |
| 12891 | /// \returns the more specialized class template partial specialization. If |
| 12892 | /// neither partial specialization is more specialized, returns NULL. |
| 12893 | ClassTemplatePartialSpecializationDecl * |
| 12894 | getMoreSpecializedPartialSpecialization( |
| 12895 | ClassTemplatePartialSpecializationDecl *PS1, |
| 12896 | ClassTemplatePartialSpecializationDecl *PS2, SourceLocation Loc); |
| 12897 | |
| 12898 | bool isMoreSpecializedThanPrimary(ClassTemplatePartialSpecializationDecl *T, |
| 12899 | sema::TemplateDeductionInfo &Info); |
| 12900 | |
| 12901 | VarTemplatePartialSpecializationDecl *getMoreSpecializedPartialSpecialization( |
| 12902 | VarTemplatePartialSpecializationDecl *PS1, |
| 12903 | VarTemplatePartialSpecializationDecl *PS2, SourceLocation Loc); |
| 12904 | |
| 12905 | bool isMoreSpecializedThanPrimary(VarTemplatePartialSpecializationDecl *T, |
| 12906 | sema::TemplateDeductionInfo &Info); |
| 12907 | |
| 12908 | bool isTemplateTemplateParameterAtLeastAsSpecializedAs( |
| 12909 | TemplateParameterList *PParam, TemplateDecl *PArg, TemplateDecl *AArg, |
| 12910 | const DefaultArguments &DefaultArgs, SourceLocation ArgLoc, |
| 12911 | bool PartialOrdering, bool *StrictPackMatch); |
| 12912 | |
| 12913 | /// Mark which template parameters are used in a given expression. |
| 12914 | /// |
| 12915 | /// \param E the expression from which template parameters will be deduced. |
| 12916 | /// |
| 12917 | /// \param Used a bit vector whose elements will be set to \c true |
| 12918 | /// to indicate when the corresponding template parameter will be |
| 12919 | /// deduced. |
| 12920 | void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced, |
| 12921 | unsigned Depth, llvm::SmallBitVector &Used); |
| 12922 | |
| 12923 | /// Mark which template parameters are named in a given expression. |
| 12924 | /// |
| 12925 | /// Unlike MarkUsedTemplateParameters, this excludes parameter that |
| 12926 | /// are used but not directly named by an expression - i.e. it excludes |
| 12927 | /// any template parameter that denotes the type of a referenced NTTP. |
| 12928 | /// |
| 12929 | /// \param Used a bit vector whose elements will be set to \c true |
| 12930 | /// to indicate when the corresponding template parameter will be |
| 12931 | /// deduced. |
| 12932 | void MarkUsedTemplateParametersForSubsumptionParameterMapping( |
| 12933 | const Expr *E, unsigned Depth, llvm::SmallBitVector &Used); |
| 12934 | |
| 12935 | /// Mark which template parameters can be deduced from a given |
| 12936 | /// template argument list. |
| 12937 | /// |
| 12938 | /// \param TemplateArgs the template argument list from which template |
| 12939 | /// parameters will be deduced. |
| 12940 | /// |
| 12941 | /// \param Used a bit vector whose elements will be set to \c true |
| 12942 | /// to indicate when the corresponding template parameter will be |
| 12943 | /// deduced. |
| 12944 | void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, |
| 12945 | bool OnlyDeduced, unsigned Depth, |
| 12946 | llvm::SmallBitVector &Used); |
| 12947 | |
| 12948 | void MarkUsedTemplateParameters(ArrayRef<TemplateArgument> TemplateArgs, |
| 12949 | unsigned Depth, llvm::SmallBitVector &Used); |
| 12950 | |
| 12951 | void MarkUsedTemplateParameters(ArrayRef<TemplateArgumentLoc> TemplateArgs, |
| 12952 | unsigned Depth, llvm::SmallBitVector &Used); |
| 12953 | |
| 12954 | void |
| 12955 | MarkDeducedTemplateParameters(const FunctionTemplateDecl *FunctionTemplate, |
| 12956 | llvm::SmallBitVector &Deduced) { |
| 12957 | return MarkDeducedTemplateParameters(Ctx&: Context, FunctionTemplate, Deduced); |
| 12958 | } |
| 12959 | |
| 12960 | /// Marks all of the template parameters that will be deduced by a |
| 12961 | /// call to the given function template. |
| 12962 | static void |
| 12963 | MarkDeducedTemplateParameters(ASTContext &Ctx, |
| 12964 | const FunctionTemplateDecl *FunctionTemplate, |
| 12965 | llvm::SmallBitVector &Deduced); |
| 12966 | |
| 12967 | /// Returns the more specialized function template according |
| 12968 | /// to the rules of function template partial ordering (C++ |
| 12969 | /// [temp.func.order]). |
| 12970 | /// |
| 12971 | /// \param FT1 the first function template |
| 12972 | /// |
| 12973 | /// \param FT2 the second function template |
| 12974 | /// |
| 12975 | /// \param TPOC the context in which we are performing partial ordering of |
| 12976 | /// function templates. |
| 12977 | /// |
| 12978 | /// \param NumCallArguments1 The number of arguments in the call to FT1, used |
| 12979 | /// only when \c TPOC is \c TPOC_Call. Does not include the object argument |
| 12980 | /// when calling a member function. |
| 12981 | /// |
| 12982 | /// \param RawObj1Ty The type of the object parameter of FT1 if a member |
| 12983 | /// function only used if \c TPOC is \c TPOC_Call and FT1 is a Function |
| 12984 | /// template from a member function |
| 12985 | /// |
| 12986 | /// \param RawObj2Ty The type of the object parameter of FT2 if a member |
| 12987 | /// function only used if \c TPOC is \c TPOC_Call and FT2 is a Function |
| 12988 | /// template from a member function |
| 12989 | /// |
| 12990 | /// \param Reversed If \c true, exactly one of FT1 and FT2 is an overload |
| 12991 | /// candidate with a reversed parameter order. In this case, the corresponding |
| 12992 | /// P/A pairs between FT1 and FT2 are reversed. |
| 12993 | /// |
| 12994 | /// \returns the more specialized function template. If neither |
| 12995 | /// template is more specialized, returns NULL. |
| 12996 | FunctionTemplateDecl *getMoreSpecializedTemplate( |
| 12997 | FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc, |
| 12998 | TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1, |
| 12999 | QualType RawObj1Ty = {}, QualType RawObj2Ty = {}, bool Reversed = false, |
| 13000 | bool PartialOverloading = false); |
| 13001 | |
| 13002 | /// Retrieve the most specialized of the given function template |
| 13003 | /// specializations. |
| 13004 | /// |
| 13005 | /// \param SpecBegin the start iterator of the function template |
| 13006 | /// specializations that we will be comparing. |
| 13007 | /// |
| 13008 | /// \param SpecEnd the end iterator of the function template |
| 13009 | /// specializations, paired with \p SpecBegin. |
| 13010 | /// |
| 13011 | /// \param Loc the location where the ambiguity or no-specializations |
| 13012 | /// diagnostic should occur. |
| 13013 | /// |
| 13014 | /// \param NoneDiag partial diagnostic used to diagnose cases where there are |
| 13015 | /// no matching candidates. |
| 13016 | /// |
| 13017 | /// \param AmbigDiag partial diagnostic used to diagnose an ambiguity, if one |
| 13018 | /// occurs. |
| 13019 | /// |
| 13020 | /// \param CandidateDiag partial diagnostic used for each function template |
| 13021 | /// specialization that is a candidate in the ambiguous ordering. One |
| 13022 | /// parameter in this diagnostic should be unbound, which will correspond to |
| 13023 | /// the string describing the template arguments for the function template |
| 13024 | /// specialization. |
| 13025 | /// |
| 13026 | /// \returns the most specialized function template specialization, if |
| 13027 | /// found. Otherwise, returns SpecEnd. |
| 13028 | UnresolvedSetIterator |
| 13029 | getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd, |
| 13030 | TemplateSpecCandidateSet &FailedCandidates, |
| 13031 | SourceLocation Loc, const PartialDiagnostic &NoneDiag, |
| 13032 | const PartialDiagnostic &AmbigDiag, |
| 13033 | const PartialDiagnostic &CandidateDiag, |
| 13034 | bool Complain = true, QualType TargetType = QualType()); |
| 13035 | |
| 13036 | /// Returns the more constrained function according to the rules of |
| 13037 | /// partial ordering by constraints (C++ [temp.constr.order]). |
| 13038 | /// |
| 13039 | /// \param FD1 the first function |
| 13040 | /// |
| 13041 | /// \param FD2 the second function |
| 13042 | /// |
| 13043 | /// \returns the more constrained function. If neither function is |
| 13044 | /// more constrained, returns NULL. |
| 13045 | FunctionDecl *getMoreConstrainedFunction(FunctionDecl *FD1, |
| 13046 | FunctionDecl *FD2); |
| 13047 | |
| 13048 | ///@} |
| 13049 | |
| 13050 | // |
| 13051 | // |
| 13052 | // ------------------------------------------------------------------------- |
| 13053 | // |
| 13054 | // |
| 13055 | |
| 13056 | /// \name C++ Template Deduction Guide |
| 13057 | /// Implementations are in SemaTemplateDeductionGuide.cpp |
| 13058 | ///@{ |
| 13059 | |
| 13060 | /// Declare implicit deduction guides for a class template if we've |
| 13061 | /// not already done so. |
| 13062 | void DeclareImplicitDeductionGuides(TemplateDecl *Template, |
| 13063 | SourceLocation Loc); |
| 13064 | |
| 13065 | FunctionTemplateDecl *DeclareAggregateDeductionGuideFromInitList( |
| 13066 | TemplateDecl *Template, MutableArrayRef<QualType> ParamTypes, |
| 13067 | SourceLocation Loc); |
| 13068 | |
| 13069 | ///@} |
| 13070 | |
| 13071 | // |
| 13072 | // |
| 13073 | // ------------------------------------------------------------------------- |
| 13074 | // |
| 13075 | // |
| 13076 | |
| 13077 | /// \name C++ Template Instantiation |
| 13078 | /// Implementations are in SemaTemplateInstantiate.cpp |
| 13079 | ///@{ |
| 13080 | |
| 13081 | public: |
| 13082 | /// A helper class for building up ExtParameterInfos. |
| 13083 | class ExtParameterInfoBuilder { |
| 13084 | SmallVector<FunctionProtoType::ExtParameterInfo, 16> Infos; |
| 13085 | bool HasInteresting = false; |
| 13086 | |
| 13087 | public: |
| 13088 | /// Set the ExtParameterInfo for the parameter at the given index, |
| 13089 | /// |
| 13090 | void set(unsigned index, FunctionProtoType::ExtParameterInfo info) { |
| 13091 | assert(Infos.size() <= index); |
| 13092 | Infos.resize(N: index); |
| 13093 | Infos.push_back(Elt: info); |
| 13094 | |
| 13095 | if (!HasInteresting) |
| 13096 | HasInteresting = (info != FunctionProtoType::ExtParameterInfo()); |
| 13097 | } |
| 13098 | |
| 13099 | /// Return a pointer (suitable for setting in an ExtProtoInfo) to the |
| 13100 | /// ExtParameterInfo array we've built up. |
| 13101 | const FunctionProtoType::ExtParameterInfo * |
| 13102 | getPointerOrNull(unsigned numParams) { |
| 13103 | if (!HasInteresting) |
| 13104 | return nullptr; |
| 13105 | Infos.resize(N: numParams); |
| 13106 | return Infos.data(); |
| 13107 | } |
| 13108 | }; |
| 13109 | |
| 13110 | /// The current instantiation scope used to store local |
| 13111 | /// variables. |
| 13112 | LocalInstantiationScope *CurrentInstantiationScope; |
| 13113 | |
| 13114 | typedef llvm::DenseMap<ParmVarDecl *, llvm::TinyPtrVector<ParmVarDecl *>> |
| 13115 | UnparsedDefaultArgInstantiationsMap; |
| 13116 | |
| 13117 | /// A mapping from parameters with unparsed default arguments to the |
| 13118 | /// set of instantiations of each parameter. |
| 13119 | /// |
| 13120 | /// This mapping is a temporary data structure used when parsing |
| 13121 | /// nested class templates or nested classes of class templates, |
| 13122 | /// where we might end up instantiating an inner class before the |
| 13123 | /// default arguments of its methods have been parsed. |
| 13124 | UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations; |
| 13125 | |
| 13126 | using InstantiatingSpecializationsKey = llvm::PointerIntPair<Decl *, 2>; |
| 13127 | |
| 13128 | struct RecursiveInstGuard { |
| 13129 | enum class Kind { |
| 13130 | Template, |
| 13131 | DefaultArgument, |
| 13132 | ExceptionSpec, |
| 13133 | }; |
| 13134 | |
| 13135 | RecursiveInstGuard(Sema &S, Decl *D, Kind Kind) |
| 13136 | : S(S), Key(D->getCanonicalDecl(), unsigned(Kind)) { |
| 13137 | auto [_, Created] = S.InstantiatingSpecializations.insert(V: Key); |
| 13138 | if (!Created) |
| 13139 | Key = {}; |
| 13140 | } |
| 13141 | |
| 13142 | ~RecursiveInstGuard() { |
| 13143 | if (Key.getOpaqueValue()) { |
| 13144 | [[maybe_unused]] bool Erased = |
| 13145 | S.InstantiatingSpecializations.erase(V: Key); |
| 13146 | assert(Erased); |
| 13147 | } |
| 13148 | } |
| 13149 | |
| 13150 | RecursiveInstGuard(const RecursiveInstGuard &) = delete; |
| 13151 | RecursiveInstGuard &operator=(const RecursiveInstGuard &) = delete; |
| 13152 | |
| 13153 | operator bool() const { return Key.getOpaqueValue() == nullptr; } |
| 13154 | |
| 13155 | private: |
| 13156 | Sema &S; |
| 13157 | Sema::InstantiatingSpecializationsKey Key; |
| 13158 | }; |
| 13159 | |
| 13160 | /// A context in which code is being synthesized (where a source location |
| 13161 | /// alone is not sufficient to identify the context). This covers template |
| 13162 | /// instantiation and various forms of implicitly-generated functions. |
| 13163 | struct CodeSynthesisContext { |
| 13164 | /// The kind of template instantiation we are performing |
| 13165 | enum SynthesisKind { |
| 13166 | /// We are instantiating a template declaration. The entity is |
| 13167 | /// the declaration we're instantiating (e.g., a CXXRecordDecl). |
| 13168 | TemplateInstantiation, |
| 13169 | |
| 13170 | /// We are instantiating a default argument for a template |
| 13171 | /// parameter. The Entity is the template parameter whose argument is |
| 13172 | /// being instantiated, the Template is the template, and the |
| 13173 | /// TemplateArgs/NumTemplateArguments provide the template arguments as |
| 13174 | /// specified. |
| 13175 | DefaultTemplateArgumentInstantiation, |
| 13176 | |
| 13177 | /// We are instantiating a default argument for a function. |
| 13178 | /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs |
| 13179 | /// provides the template arguments as specified. |
| 13180 | DefaultFunctionArgumentInstantiation, |
| 13181 | |
| 13182 | /// We are substituting explicit template arguments provided for |
| 13183 | /// a function template. The entity is a FunctionTemplateDecl. |
| 13184 | ExplicitTemplateArgumentSubstitution, |
| 13185 | |
| 13186 | /// We are substituting template argument determined as part of |
| 13187 | /// template argument deduction for either a class template |
| 13188 | /// partial specialization or a function template. The |
| 13189 | /// Entity is either a {Class|Var}TemplatePartialSpecializationDecl or |
| 13190 | /// a TemplateDecl. |
| 13191 | DeducedTemplateArgumentSubstitution, |
| 13192 | |
| 13193 | /// We are substituting into a lambda expression. |
| 13194 | LambdaExpressionSubstitution, |
| 13195 | |
| 13196 | /// We are substituting prior template arguments into a new |
| 13197 | /// template parameter. The template parameter itself is either a |
| 13198 | /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. |
| 13199 | PriorTemplateArgumentSubstitution, |
| 13200 | |
| 13201 | /// We are checking the validity of a default template argument that |
| 13202 | /// has been used when naming a template-id. |
| 13203 | DefaultTemplateArgumentChecking, |
| 13204 | |
| 13205 | /// We are computing the exception specification for a defaulted special |
| 13206 | /// member function. |
| 13207 | ExceptionSpecEvaluation, |
| 13208 | |
| 13209 | /// We are instantiating the exception specification for a function |
| 13210 | /// template which was deferred until it was needed. |
| 13211 | ExceptionSpecInstantiation, |
| 13212 | |
| 13213 | /// We are instantiating a requirement of a requires expression. |
| 13214 | RequirementInstantiation, |
| 13215 | |
| 13216 | /// We are checking the satisfaction of a nested requirement of a requires |
| 13217 | /// expression. |
| 13218 | NestedRequirementConstraintsCheck, |
| 13219 | |
| 13220 | /// We are declaring an implicit special member function. |
| 13221 | DeclaringSpecialMember, |
| 13222 | |
| 13223 | /// We are declaring an implicit 'operator==' for a defaulted |
| 13224 | /// 'operator<=>'. |
| 13225 | DeclaringImplicitEqualityComparison, |
| 13226 | |
| 13227 | /// We are defining a synthesized function (such as a defaulted special |
| 13228 | /// member). |
| 13229 | DefiningSynthesizedFunction, |
| 13230 | |
| 13231 | // We are checking the constraints associated with a constrained entity or |
| 13232 | // the constraint expression of a concept. This includes the checks that |
| 13233 | // atomic constraints have the type 'bool' and that they can be constant |
| 13234 | // evaluated. |
| 13235 | ConstraintsCheck, |
| 13236 | |
| 13237 | // We are substituting template arguments into a constraint expression. |
| 13238 | ConstraintSubstitution, |
| 13239 | |
| 13240 | // We are normalizing a constraint expression. |
| 13241 | ConstraintNormalization, |
| 13242 | |
| 13243 | // Instantiating a Requires Expression parameter clause. |
| 13244 | RequirementParameterInstantiation, |
| 13245 | |
| 13246 | // We are substituting into the parameter mapping of an atomic constraint |
| 13247 | // during normalization. |
| 13248 | ParameterMappingSubstitution, |
| 13249 | |
| 13250 | /// We are rewriting a comparison operator in terms of an operator<=>. |
| 13251 | RewritingOperatorAsSpaceship, |
| 13252 | |
| 13253 | /// We are initializing a structured binding. |
| 13254 | InitializingStructuredBinding, |
| 13255 | |
| 13256 | /// We are marking a class as __dllexport. |
| 13257 | MarkingClassDllexported, |
| 13258 | |
| 13259 | /// We are building an implied call from __builtin_dump_struct. The |
| 13260 | /// arguments are in CallArgs. |
| 13261 | BuildingBuiltinDumpStructCall, |
| 13262 | |
| 13263 | /// Added for Template instantiation observation. |
| 13264 | /// Memoization means we are _not_ instantiating a template because |
| 13265 | /// it is already instantiated (but we entered a context where we |
| 13266 | /// would have had to if it was not already instantiated). |
| 13267 | Memoization, |
| 13268 | |
| 13269 | /// We are building deduction guides for a class. |
| 13270 | BuildingDeductionGuides, |
| 13271 | |
| 13272 | /// We are instantiating a type alias template declaration. |
| 13273 | TypeAliasTemplateInstantiation, |
| 13274 | |
| 13275 | /// We are performing partial ordering for template template parameters. |
| 13276 | PartialOrderingTTP, |
| 13277 | } Kind; |
| 13278 | |
| 13279 | /// Whether we're substituting into constraints. |
| 13280 | bool InConstraintSubstitution; |
| 13281 | |
| 13282 | /// Whether we're substituting into the parameter mapping of a constraint. |
| 13283 | bool InParameterMappingSubstitution; |
| 13284 | |
| 13285 | /// The point of instantiation or synthesis within the source code. |
| 13286 | SourceLocation PointOfInstantiation; |
| 13287 | |
| 13288 | /// The entity that is being synthesized. |
| 13289 | Decl *Entity; |
| 13290 | |
| 13291 | /// The template (or partial specialization) in which we are |
| 13292 | /// performing the instantiation, for substitutions of prior template |
| 13293 | /// arguments. |
| 13294 | NamedDecl *Template; |
| 13295 | |
| 13296 | union { |
| 13297 | /// The list of template arguments we are substituting, if they |
| 13298 | /// are not part of the entity. |
| 13299 | const TemplateArgument *TemplateArgs; |
| 13300 | |
| 13301 | /// The list of argument expressions in a synthesized call. |
| 13302 | const Expr *const *CallArgs; |
| 13303 | }; |
| 13304 | |
| 13305 | // FIXME: Wrap this union around more members, or perhaps store the |
| 13306 | // kind-specific members in the RAII object owning the context. |
| 13307 | union { |
| 13308 | /// The number of template arguments in TemplateArgs. |
| 13309 | unsigned NumTemplateArgs; |
| 13310 | |
| 13311 | /// The number of expressions in CallArgs. |
| 13312 | unsigned NumCallArgs; |
| 13313 | |
| 13314 | /// The special member being declared or defined. |
| 13315 | CXXSpecialMemberKind SpecialMember; |
| 13316 | }; |
| 13317 | |
| 13318 | ArrayRef<TemplateArgument> template_arguments() const { |
| 13319 | assert(Kind != DeclaringSpecialMember); |
| 13320 | return {TemplateArgs, NumTemplateArgs}; |
| 13321 | } |
| 13322 | |
| 13323 | /// The source range that covers the construct that cause |
| 13324 | /// the instantiation, e.g., the template-id that causes a class |
| 13325 | /// template instantiation. |
| 13326 | SourceRange InstantiationRange; |
| 13327 | |
| 13328 | CodeSynthesisContext() |
| 13329 | : Kind(TemplateInstantiation), InConstraintSubstitution(false), |
| 13330 | InParameterMappingSubstitution(false), Entity(nullptr), |
| 13331 | Template(nullptr), TemplateArgs(nullptr), NumTemplateArgs(0) {} |
| 13332 | |
| 13333 | /// Determines whether this template is an actual instantiation |
| 13334 | /// that should be counted toward the maximum instantiation depth. |
| 13335 | bool isInstantiationRecord() const; |
| 13336 | }; |
| 13337 | |
| 13338 | /// A stack object to be created when performing template |
| 13339 | /// instantiation. |
| 13340 | /// |
| 13341 | /// Construction of an object of type \c InstantiatingTemplate |
| 13342 | /// pushes the current instantiation onto the stack of active |
| 13343 | /// instantiations. If the size of this stack exceeds the maximum |
| 13344 | /// number of recursive template instantiations, construction |
| 13345 | /// produces an error and evaluates true. |
| 13346 | /// |
| 13347 | /// Destruction of this object will pop the named instantiation off |
| 13348 | /// the stack. |
| 13349 | struct InstantiatingTemplate { |
| 13350 | /// Note that we are instantiating a class template, |
| 13351 | /// function template, variable template, alias template, |
| 13352 | /// or a member thereof. |
| 13353 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13354 | Decl *Entity, |
| 13355 | SourceRange InstantiationRange = SourceRange()); |
| 13356 | |
| 13357 | struct ExceptionSpecification {}; |
| 13358 | /// Note that we are instantiating an exception specification |
| 13359 | /// of a function template. |
| 13360 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13361 | FunctionDecl *Entity, ExceptionSpecification, |
| 13362 | SourceRange InstantiationRange = SourceRange()); |
| 13363 | |
| 13364 | /// Note that we are instantiating a type alias template declaration. |
| 13365 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13366 | TypeAliasTemplateDecl *Entity, |
| 13367 | ArrayRef<TemplateArgument> TemplateArgs, |
| 13368 | SourceRange InstantiationRange = SourceRange()); |
| 13369 | |
| 13370 | /// Note that we are instantiating a default argument in a |
| 13371 | /// template-id. |
| 13372 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13373 | TemplateParameter Param, TemplateDecl *Template, |
| 13374 | ArrayRef<TemplateArgument> TemplateArgs, |
| 13375 | SourceRange InstantiationRange = SourceRange()); |
| 13376 | |
| 13377 | /// Note that we are substituting either explicitly-specified or |
| 13378 | /// deduced template arguments during function template argument deduction. |
| 13379 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13380 | FunctionTemplateDecl *FunctionTemplate, |
| 13381 | ArrayRef<TemplateArgument> TemplateArgs, |
| 13382 | CodeSynthesisContext::SynthesisKind Kind, |
| 13383 | SourceRange InstantiationRange = SourceRange()); |
| 13384 | |
| 13385 | /// Note that we are instantiating as part of template |
| 13386 | /// argument deduction for a class template declaration. |
| 13387 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13388 | TemplateDecl *Template, |
| 13389 | ArrayRef<TemplateArgument> TemplateArgs, |
| 13390 | SourceRange InstantiationRange = SourceRange()); |
| 13391 | |
| 13392 | /// Note that we are instantiating as part of template |
| 13393 | /// argument deduction for a class template partial |
| 13394 | /// specialization. |
| 13395 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13396 | ClassTemplatePartialSpecializationDecl *PartialSpec, |
| 13397 | ArrayRef<TemplateArgument> TemplateArgs, |
| 13398 | SourceRange InstantiationRange = SourceRange()); |
| 13399 | |
| 13400 | /// Note that we are instantiating as part of template |
| 13401 | /// argument deduction for a variable template partial |
| 13402 | /// specialization. |
| 13403 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13404 | VarTemplatePartialSpecializationDecl *PartialSpec, |
| 13405 | ArrayRef<TemplateArgument> TemplateArgs, |
| 13406 | SourceRange InstantiationRange = SourceRange()); |
| 13407 | |
| 13408 | /// Note that we are instantiating a default argument for a function |
| 13409 | /// parameter. |
| 13410 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13411 | ParmVarDecl *Param, |
| 13412 | ArrayRef<TemplateArgument> TemplateArgs, |
| 13413 | SourceRange InstantiationRange = SourceRange()); |
| 13414 | |
| 13415 | /// Note that we are substituting prior template arguments into a |
| 13416 | /// non-type parameter. |
| 13417 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13418 | NamedDecl *Template, NonTypeTemplateParmDecl *Param, |
| 13419 | ArrayRef<TemplateArgument> TemplateArgs, |
| 13420 | SourceRange InstantiationRange); |
| 13421 | |
| 13422 | /// Note that we are substituting prior template arguments into a |
| 13423 | /// template template parameter. |
| 13424 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13425 | NamedDecl *Template, TemplateTemplateParmDecl *Param, |
| 13426 | ArrayRef<TemplateArgument> TemplateArgs, |
| 13427 | SourceRange InstantiationRange); |
| 13428 | |
| 13429 | /// Note that we are checking the default template argument |
| 13430 | /// against the template parameter for a given template-id. |
| 13431 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13432 | TemplateDecl *Template, NamedDecl *Param, |
| 13433 | ArrayRef<TemplateArgument> TemplateArgs, |
| 13434 | SourceRange InstantiationRange); |
| 13435 | |
| 13436 | struct ConstraintsCheck {}; |
| 13437 | /// \brief Note that we are checking the constraints associated with some |
| 13438 | /// constrained entity (a concept declaration or a template with associated |
| 13439 | /// constraints). |
| 13440 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13441 | ConstraintsCheck, NamedDecl *Template, |
| 13442 | ArrayRef<TemplateArgument> TemplateArgs, |
| 13443 | SourceRange InstantiationRange); |
| 13444 | |
| 13445 | struct ConstraintSubstitution {}; |
| 13446 | /// \brief Note that we are checking a constraint expression associated |
| 13447 | /// with a template declaration or as part of the satisfaction check of a |
| 13448 | /// concept. |
| 13449 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13450 | ConstraintSubstitution, NamedDecl *Template, |
| 13451 | SourceRange InstantiationRange); |
| 13452 | |
| 13453 | struct ConstraintNormalization {}; |
| 13454 | /// \brief Note that we are normalizing a constraint expression. |
| 13455 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13456 | ConstraintNormalization, NamedDecl *Template, |
| 13457 | SourceRange InstantiationRange); |
| 13458 | |
| 13459 | struct ParameterMappingSubstitution {}; |
| 13460 | /// \brief Note that we are subtituting into the parameter mapping of an |
| 13461 | /// atomic constraint during constraint normalization. |
| 13462 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13463 | ParameterMappingSubstitution, NamedDecl *Template, |
| 13464 | SourceRange InstantiationRange); |
| 13465 | |
| 13466 | /// \brief Note that we are substituting template arguments into a part of |
| 13467 | /// a requirement of a requires expression. |
| 13468 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13469 | concepts::Requirement *Req, |
| 13470 | SourceRange InstantiationRange = SourceRange()); |
| 13471 | |
| 13472 | /// \brief Note that we are checking the satisfaction of the constraint |
| 13473 | /// expression inside of a nested requirement. |
| 13474 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13475 | concepts::NestedRequirement *Req, ConstraintsCheck, |
| 13476 | SourceRange InstantiationRange = SourceRange()); |
| 13477 | |
| 13478 | /// \brief Note that we are checking a requires clause. |
| 13479 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13480 | const RequiresExpr *E, |
| 13481 | SourceRange InstantiationRange); |
| 13482 | |
| 13483 | struct BuildingDeductionGuidesTag {}; |
| 13484 | /// \brief Note that we are building deduction guides. |
| 13485 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 13486 | TemplateDecl *Entity, BuildingDeductionGuidesTag, |
| 13487 | SourceRange InstantiationRange = SourceRange()); |
| 13488 | |
| 13489 | struct PartialOrderingTTP {}; |
| 13490 | /// \brief Note that we are partial ordering template template parameters. |
| 13491 | InstantiatingTemplate(Sema &SemaRef, SourceLocation ArgLoc, |
| 13492 | PartialOrderingTTP, TemplateDecl *PArg, |
| 13493 | SourceRange InstantiationRange = SourceRange()); |
| 13494 | |
| 13495 | /// Note that we have finished instantiating this template. |
| 13496 | void Clear(); |
| 13497 | |
| 13498 | ~InstantiatingTemplate() { Clear(); } |
| 13499 | |
| 13500 | /// Determines whether we have exceeded the maximum |
| 13501 | /// recursive template instantiations. |
| 13502 | bool isInvalid() const { return Invalid; } |
| 13503 | |
| 13504 | private: |
| 13505 | Sema &SemaRef; |
| 13506 | bool Invalid; |
| 13507 | |
| 13508 | InstantiatingTemplate(Sema &SemaRef, |
| 13509 | CodeSynthesisContext::SynthesisKind Kind, |
| 13510 | SourceLocation PointOfInstantiation, |
| 13511 | SourceRange InstantiationRange, Decl *Entity, |
| 13512 | NamedDecl *Template = nullptr, |
| 13513 | ArrayRef<TemplateArgument> TemplateArgs = {}); |
| 13514 | |
| 13515 | InstantiatingTemplate(const InstantiatingTemplate &) = delete; |
| 13516 | |
| 13517 | InstantiatingTemplate &operator=(const InstantiatingTemplate &) = delete; |
| 13518 | }; |
| 13519 | |
| 13520 | bool SubstTemplateArgument(const TemplateArgumentLoc &Input, |
| 13521 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 13522 | TemplateArgumentLoc &Output, |
| 13523 | SourceLocation Loc = {}, |
| 13524 | const DeclarationName &Entity = {}); |
| 13525 | bool |
| 13526 | SubstTemplateArguments(ArrayRef<TemplateArgumentLoc> Args, |
| 13527 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 13528 | TemplateArgumentListInfo &Outputs); |
| 13529 | |
| 13530 | /// Substitute concept template arguments in the constraint expression |
| 13531 | /// of a concept-id. This is used to implement [temp.constr.normal]. |
| 13532 | ExprResult |
| 13533 | SubstConceptTemplateArguments(const ConceptSpecializationExpr *CSE, |
| 13534 | const Expr *ConstraintExpr, |
| 13535 | const MultiLevelTemplateArgumentList &MLTAL); |
| 13536 | |
| 13537 | bool SubstTemplateArgumentsInParameterMapping( |
| 13538 | ArrayRef<TemplateArgumentLoc> Args, SourceLocation BaseLoc, |
| 13539 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 13540 | TemplateArgumentListInfo &Out); |
| 13541 | |
| 13542 | /// Retrieve the template argument list(s) that should be used to |
| 13543 | /// instantiate the definition of the given declaration. |
| 13544 | /// |
| 13545 | /// \param ND the declaration for which we are computing template |
| 13546 | /// instantiation arguments. |
| 13547 | /// |
| 13548 | /// \param DC In the event we don't HAVE a declaration yet, we instead provide |
| 13549 | /// the decl context where it will be created. In this case, the `Innermost` |
| 13550 | /// should likely be provided. If ND is non-null, this is ignored. |
| 13551 | /// |
| 13552 | /// \param Innermost if non-NULL, specifies a template argument list for the |
| 13553 | /// template declaration passed as ND. |
| 13554 | /// |
| 13555 | /// \param RelativeToPrimary true if we should get the template |
| 13556 | /// arguments relative to the primary template, even when we're |
| 13557 | /// dealing with a specialization. This is only relevant for function |
| 13558 | /// template specializations. |
| 13559 | /// |
| 13560 | /// \param Pattern If non-NULL, indicates the pattern from which we will be |
| 13561 | /// instantiating the definition of the given declaration, \p ND. This is |
| 13562 | /// used to determine the proper set of template instantiation arguments for |
| 13563 | /// friend function template specializations. |
| 13564 | /// |
| 13565 | /// \param ForConstraintInstantiation when collecting arguments, |
| 13566 | /// ForConstraintInstantiation indicates we should continue looking when |
| 13567 | /// encountering a lambda generic call operator, and continue looking for |
| 13568 | /// arguments on an enclosing class template. |
| 13569 | /// |
| 13570 | /// \param SkipForSpecialization when specified, any template specializations |
| 13571 | /// in a traversal would be ignored. |
| 13572 | /// |
| 13573 | /// \param ForDefaultArgumentSubstitution indicates we should continue looking |
| 13574 | /// when encountering a specialized member function template, rather than |
| 13575 | /// returning immediately. |
| 13576 | MultiLevelTemplateArgumentList getTemplateInstantiationArgs( |
| 13577 | const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false, |
| 13578 | std::optional<ArrayRef<TemplateArgument>> Innermost = std::nullopt, |
| 13579 | bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr, |
| 13580 | bool ForConstraintInstantiation = false, |
| 13581 | bool SkipForSpecialization = false, |
| 13582 | bool ForDefaultArgumentSubstitution = false); |
| 13583 | |
| 13584 | /// RAII object to handle the state changes required to synthesize |
| 13585 | /// a function body. |
| 13586 | class SynthesizedFunctionScope { |
| 13587 | Sema &S; |
| 13588 | Sema::ContextRAII SavedContext; |
| 13589 | bool PushedCodeSynthesisContext = false; |
| 13590 | |
| 13591 | public: |
| 13592 | SynthesizedFunctionScope(Sema &S, DeclContext *DC) |
| 13593 | : S(S), SavedContext(S, DC) { |
| 13594 | auto *FD = dyn_cast<FunctionDecl>(Val: DC); |
| 13595 | S.PushFunctionScope(); |
| 13596 | S.PushExpressionEvaluationContextForFunction( |
| 13597 | NewContext: ExpressionEvaluationContext::PotentiallyEvaluated, FD); |
| 13598 | if (FD) |
| 13599 | FD->setWillHaveBody(true); |
| 13600 | else |
| 13601 | assert(isa<ObjCMethodDecl>(DC)); |
| 13602 | } |
| 13603 | |
| 13604 | void addContextNote(SourceLocation UseLoc) { |
| 13605 | assert(!PushedCodeSynthesisContext); |
| 13606 | |
| 13607 | Sema::CodeSynthesisContext Ctx; |
| 13608 | Ctx.Kind = Sema::CodeSynthesisContext::DefiningSynthesizedFunction; |
| 13609 | Ctx.PointOfInstantiation = UseLoc; |
| 13610 | Ctx.Entity = cast<Decl>(Val: S.CurContext); |
| 13611 | S.pushCodeSynthesisContext(Ctx); |
| 13612 | |
| 13613 | PushedCodeSynthesisContext = true; |
| 13614 | } |
| 13615 | |
| 13616 | ~SynthesizedFunctionScope() { |
| 13617 | if (PushedCodeSynthesisContext) |
| 13618 | S.popCodeSynthesisContext(); |
| 13619 | if (auto *FD = dyn_cast<FunctionDecl>(Val: S.CurContext)) { |
| 13620 | FD->setWillHaveBody(false); |
| 13621 | S.CheckImmediateEscalatingFunctionDefinition(FD, FSI: S.getCurFunction()); |
| 13622 | } |
| 13623 | S.PopExpressionEvaluationContext(); |
| 13624 | S.PopFunctionScopeInfo(); |
| 13625 | } |
| 13626 | |
| 13627 | SynthesizedFunctionScope(const SynthesizedFunctionScope &) = delete; |
| 13628 | SynthesizedFunctionScope & |
| 13629 | operator=(const SynthesizedFunctionScope &) = delete; |
| 13630 | }; |
| 13631 | |
| 13632 | /// List of active code synthesis contexts. |
| 13633 | /// |
| 13634 | /// This vector is treated as a stack. As synthesis of one entity requires |
| 13635 | /// synthesis of another, additional contexts are pushed onto the stack. |
| 13636 | SmallVector<CodeSynthesisContext, 16> CodeSynthesisContexts; |
| 13637 | |
| 13638 | /// Specializations whose definitions are currently being instantiated. |
| 13639 | llvm::DenseSet<InstantiatingSpecializationsKey> InstantiatingSpecializations; |
| 13640 | |
| 13641 | /// Non-dependent types used in templates that have already been instantiated |
| 13642 | /// by some template instantiation. |
| 13643 | llvm::DenseSet<QualType> InstantiatedNonDependentTypes; |
| 13644 | |
| 13645 | /// Extra modules inspected when performing a lookup during a template |
| 13646 | /// instantiation. Computed lazily. |
| 13647 | SmallVector<Module *, 16> CodeSynthesisContextLookupModules; |
| 13648 | |
| 13649 | /// Cache of additional modules that should be used for name lookup |
| 13650 | /// within the current template instantiation. Computed lazily; use |
| 13651 | /// getLookupModules() to get a complete set. |
| 13652 | llvm::DenseSet<Module *> LookupModulesCache; |
| 13653 | |
| 13654 | /// Map from the most recent declaration of a namespace to the most |
| 13655 | /// recent visible declaration of that namespace. |
| 13656 | llvm::DenseMap<NamedDecl *, NamedDecl *> VisibleNamespaceCache; |
| 13657 | |
| 13658 | SFINAETrap *CurrentSFINAEContext = nullptr; |
| 13659 | |
| 13660 | /// The number of \p CodeSynthesisContexts that are not template |
| 13661 | /// instantiations and, therefore, should not be counted as part of the |
| 13662 | /// instantiation depth. |
| 13663 | /// |
| 13664 | /// When the instantiation depth reaches the user-configurable limit |
| 13665 | /// \p LangOptions::InstantiationDepth we will abort instantiation. |
| 13666 | // FIXME: Should we have a similar limit for other forms of synthesis? |
| 13667 | unsigned NonInstantiationEntries; |
| 13668 | |
| 13669 | /// The depth of the context stack at the point when the most recent |
| 13670 | /// error or warning was produced. |
| 13671 | /// |
| 13672 | /// This value is used to suppress printing of redundant context stacks |
| 13673 | /// when there are multiple errors or warnings in the same instantiation. |
| 13674 | // FIXME: Does this belong in Sema? It's tough to implement it anywhere else. |
| 13675 | unsigned LastEmittedCodeSynthesisContextDepth = 0; |
| 13676 | |
| 13677 | /// The template instantiation callbacks to trace or track |
| 13678 | /// instantiations (objects can be chained). |
| 13679 | /// |
| 13680 | /// This callbacks is used to print, trace or track template |
| 13681 | /// instantiations as they are being constructed. |
| 13682 | std::vector<std::unique_ptr<TemplateInstantiationCallback>> |
| 13683 | TemplateInstCallbacks; |
| 13684 | |
| 13685 | /// The current index into pack expansion arguments that will be |
| 13686 | /// used for substitution of parameter packs. |
| 13687 | /// |
| 13688 | /// The pack expansion index will be none to indicate that parameter packs |
| 13689 | /// should be instantiated as themselves. Otherwise, the index specifies |
| 13690 | /// which argument within the parameter pack will be used for substitution. |
| 13691 | UnsignedOrNone ArgPackSubstIndex; |
| 13692 | |
| 13693 | /// RAII object used to change the argument pack substitution index |
| 13694 | /// within a \c Sema object. |
| 13695 | /// |
| 13696 | /// See \c ArgPackSubstIndex for more information. |
| 13697 | class ArgPackSubstIndexRAII { |
| 13698 | Sema &Self; |
| 13699 | UnsignedOrNone OldSubstIndex; |
| 13700 | |
| 13701 | public: |
| 13702 | ArgPackSubstIndexRAII(Sema &Self, UnsignedOrNone NewSubstIndex) |
| 13703 | : Self(Self), |
| 13704 | OldSubstIndex(std::exchange(obj&: Self.ArgPackSubstIndex, new_val&: NewSubstIndex)) {} |
| 13705 | |
| 13706 | ~ArgPackSubstIndexRAII() { Self.ArgPackSubstIndex = OldSubstIndex; } |
| 13707 | ArgPackSubstIndexRAII(const ArgPackSubstIndexRAII &) = delete; |
| 13708 | ArgPackSubstIndexRAII &operator=(const ArgPackSubstIndexRAII &) = delete; |
| 13709 | }; |
| 13710 | |
| 13711 | bool pushCodeSynthesisContext(CodeSynthesisContext Ctx); |
| 13712 | void popCodeSynthesisContext(); |
| 13713 | |
| 13714 | void PrintContextStack(InstantiationContextDiagFuncRef DiagFunc) { |
| 13715 | if (!CodeSynthesisContexts.empty() && |
| 13716 | CodeSynthesisContexts.size() != LastEmittedCodeSynthesisContextDepth) { |
| 13717 | PrintInstantiationStack(DiagFunc); |
| 13718 | LastEmittedCodeSynthesisContextDepth = CodeSynthesisContexts.size(); |
| 13719 | } |
| 13720 | if (PragmaAttributeCurrentTargetDecl) |
| 13721 | PrintPragmaAttributeInstantiationPoint(DiagFunc); |
| 13722 | } |
| 13723 | void PrintContextStack() { PrintContextStack(DiagFunc: getDefaultDiagFunc()); } |
| 13724 | /// Prints the current instantiation stack through a series of |
| 13725 | /// notes. |
| 13726 | void PrintInstantiationStack(InstantiationContextDiagFuncRef DiagFunc); |
| 13727 | void PrintInstantiationStack() { |
| 13728 | PrintInstantiationStack(DiagFunc: getDefaultDiagFunc()); |
| 13729 | } |
| 13730 | |
| 13731 | /// Returns a pointer to the current SFINAE context, if any. |
| 13732 | [[nodiscard]] SFINAETrap *getSFINAEContext() const { |
| 13733 | return CurrentSFINAEContext; |
| 13734 | } |
| 13735 | [[nodiscard]] bool isSFINAEContext() const { |
| 13736 | return CurrentSFINAEContext != nullptr; |
| 13737 | } |
| 13738 | |
| 13739 | /// Perform substitution on the type T with a given set of template |
| 13740 | /// arguments. |
| 13741 | /// |
| 13742 | /// This routine substitutes the given template arguments into the |
| 13743 | /// type T and produces the instantiated type. |
| 13744 | /// |
| 13745 | /// \param T the type into which the template arguments will be |
| 13746 | /// substituted. If this type is not dependent, it will be returned |
| 13747 | /// immediately. |
| 13748 | /// |
| 13749 | /// \param Args the template arguments that will be |
| 13750 | /// substituted for the top-level template parameters within T. |
| 13751 | /// |
| 13752 | /// \param Loc the location in the source code where this substitution |
| 13753 | /// is being performed. It will typically be the location of the |
| 13754 | /// declarator (if we're instantiating the type of some declaration) |
| 13755 | /// or the location of the type in the source code (if, e.g., we're |
| 13756 | /// instantiating the type of a cast expression). |
| 13757 | /// |
| 13758 | /// \param Entity the name of the entity associated with a declaration |
| 13759 | /// being instantiated (if any). May be empty to indicate that there |
| 13760 | /// is no such entity (if, e.g., this is a type that occurs as part of |
| 13761 | /// a cast expression) or that the entity has no name (e.g., an |
| 13762 | /// unnamed function parameter). |
| 13763 | /// |
| 13764 | /// \param AllowDeducedTST Whether a DeducedTemplateSpecializationType is |
| 13765 | /// acceptable as the top level type of the result. |
| 13766 | /// |
| 13767 | /// \param IsIncompleteSubstitution If provided, the pointee will be set |
| 13768 | /// whenever substitution would perform a replacement with a null or |
| 13769 | /// non-existent template argument. |
| 13770 | /// |
| 13771 | /// \returns If the instantiation succeeds, the instantiated |
| 13772 | /// type. Otherwise, produces diagnostics and returns a NULL type. |
| 13773 | TypeSourceInfo *SubstType(TypeSourceInfo *T, |
| 13774 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 13775 | SourceLocation Loc, DeclarationName Entity, |
| 13776 | bool AllowDeducedTST = false); |
| 13777 | |
| 13778 | QualType SubstType(QualType T, |
| 13779 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 13780 | SourceLocation Loc, DeclarationName Entity, |
| 13781 | bool *IsIncompleteSubstitution = nullptr); |
| 13782 | |
| 13783 | TypeSourceInfo *SubstType(TypeLoc TL, |
| 13784 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 13785 | SourceLocation Loc, DeclarationName Entity); |
| 13786 | |
| 13787 | /// A form of SubstType intended specifically for instantiating the |
| 13788 | /// type of a FunctionDecl. Its purpose is solely to force the |
| 13789 | /// instantiation of default-argument expressions and to avoid |
| 13790 | /// instantiating an exception-specification. |
| 13791 | TypeSourceInfo *SubstFunctionDeclType( |
| 13792 | TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs, |
| 13793 | SourceLocation Loc, DeclarationName Entity, CXXRecordDecl *ThisContext, |
| 13794 | Qualifiers ThisTypeQuals, bool EvaluateConstraints = true); |
| 13795 | void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, |
| 13796 | const MultiLevelTemplateArgumentList &Args); |
| 13797 | bool SubstExceptionSpec(SourceLocation Loc, |
| 13798 | FunctionProtoType::ExceptionSpecInfo &ESI, |
| 13799 | SmallVectorImpl<QualType> &ExceptionStorage, |
| 13800 | const MultiLevelTemplateArgumentList &Args); |
| 13801 | ParmVarDecl * |
| 13802 | SubstParmVarDecl(ParmVarDecl *D, |
| 13803 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 13804 | int indexAdjustment, UnsignedOrNone NumExpansions, |
| 13805 | bool ExpectParameterPack, bool EvaluateConstraints = true); |
| 13806 | |
| 13807 | /// Substitute the given template arguments into the given set of |
| 13808 | /// parameters, producing the set of parameter types that would be generated |
| 13809 | /// from such a substitution. |
| 13810 | bool SubstParmTypes(SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
| 13811 | const FunctionProtoType::ExtParameterInfo *ExtParamInfos, |
| 13812 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 13813 | SmallVectorImpl<QualType> &ParamTypes, |
| 13814 | SmallVectorImpl<ParmVarDecl *> *OutParams, |
| 13815 | ExtParameterInfoBuilder &ParamInfos); |
| 13816 | |
| 13817 | /// Substitute the given template arguments into the default argument. |
| 13818 | bool SubstDefaultArgument(SourceLocation Loc, ParmVarDecl *Param, |
| 13819 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 13820 | bool ForCallExpr = false); |
| 13821 | ExprResult SubstExpr(Expr *E, |
| 13822 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 13823 | /// Substitute an expression as if it is a address-of-operand, which makes it |
| 13824 | /// act like a CXXIdExpression rather than an attempt to call. |
| 13825 | ExprResult SubstCXXIdExpr(Expr *E, |
| 13826 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 13827 | |
| 13828 | // A RAII type used by the TemplateDeclInstantiator and TemplateInstantiator |
| 13829 | // to disable constraint evaluation, then restore the state. |
| 13830 | template <typename InstTy> struct ConstraintEvalRAII { |
| 13831 | InstTy &TI; |
| 13832 | bool OldValue; |
| 13833 | |
| 13834 | ConstraintEvalRAII(InstTy &TI) |
| 13835 | : TI(TI), OldValue(TI.getEvaluateConstraints()) { |
| 13836 | TI.setEvaluateConstraints(false); |
| 13837 | } |
| 13838 | ~ConstraintEvalRAII() { TI.setEvaluateConstraints(OldValue); } |
| 13839 | ConstraintEvalRAII(const ConstraintEvalRAII &) = delete; |
| 13840 | ConstraintEvalRAII &operator=(const ConstraintEvalRAII &) = delete; |
| 13841 | }; |
| 13842 | |
| 13843 | // Must be used instead of SubstExpr at 'constraint checking' time. |
| 13844 | ExprResult |
| 13845 | SubstConstraintExpr(Expr *E, |
| 13846 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 13847 | // Unlike the above, this does not evaluate constraints. |
| 13848 | ExprResult SubstConstraintExprWithoutSatisfaction( |
| 13849 | Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs); |
| 13850 | |
| 13851 | /// Substitute the given template arguments into a list of |
| 13852 | /// expressions, expanding pack expansions if required. |
| 13853 | /// |
| 13854 | /// \param Exprs The list of expressions to substitute into. |
| 13855 | /// |
| 13856 | /// \param IsCall Whether this is some form of call, in which case |
| 13857 | /// default arguments will be dropped. |
| 13858 | /// |
| 13859 | /// \param TemplateArgs The set of template arguments to substitute. |
| 13860 | /// |
| 13861 | /// \param Outputs Will receive all of the substituted arguments. |
| 13862 | /// |
| 13863 | /// \returns true if an error occurred, false otherwise. |
| 13864 | bool SubstExprs(ArrayRef<Expr *> Exprs, bool IsCall, |
| 13865 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 13866 | SmallVectorImpl<Expr *> &Outputs); |
| 13867 | |
| 13868 | StmtResult SubstStmt(Stmt *S, |
| 13869 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 13870 | |
| 13871 | ExprResult |
| 13872 | SubstInitializer(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs, |
| 13873 | bool CXXDirectInit); |
| 13874 | |
| 13875 | /// Perform substitution on the base class specifiers of the |
| 13876 | /// given class template specialization. |
| 13877 | /// |
| 13878 | /// Produces a diagnostic and returns true on error, returns false and |
| 13879 | /// attaches the instantiated base classes to the class template |
| 13880 | /// specialization if successful. |
| 13881 | bool SubstBaseSpecifiers(CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, |
| 13882 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 13883 | |
| 13884 | /// Instantiate the definition of a class from a given pattern. |
| 13885 | /// |
| 13886 | /// \param PointOfInstantiation The point of instantiation within the |
| 13887 | /// source code. |
| 13888 | /// |
| 13889 | /// \param Instantiation is the declaration whose definition is being |
| 13890 | /// instantiated. This will be either a class template specialization |
| 13891 | /// or a member class of a class template specialization. |
| 13892 | /// |
| 13893 | /// \param Pattern is the pattern from which the instantiation |
| 13894 | /// occurs. This will be either the declaration of a class template or |
| 13895 | /// the declaration of a member class of a class template. |
| 13896 | /// |
| 13897 | /// \param TemplateArgs The template arguments to be substituted into |
| 13898 | /// the pattern. |
| 13899 | /// |
| 13900 | /// \param TSK the kind of implicit or explicit instantiation to perform. |
| 13901 | /// |
| 13902 | /// \param Complain whether to complain if the class cannot be instantiated |
| 13903 | /// due to the lack of a definition. |
| 13904 | /// |
| 13905 | /// \returns true if an error occurred, false otherwise. |
| 13906 | bool InstantiateClass(SourceLocation PointOfInstantiation, |
| 13907 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, |
| 13908 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 13909 | TemplateSpecializationKind TSK, bool Complain = true); |
| 13910 | |
| 13911 | private: |
| 13912 | bool InstantiateClassImpl(SourceLocation PointOfInstantiation, |
| 13913 | CXXRecordDecl *Instantiation, |
| 13914 | CXXRecordDecl *Pattern, |
| 13915 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 13916 | TemplateSpecializationKind TSK, bool Complain); |
| 13917 | |
| 13918 | public: |
| 13919 | /// Instantiate the definition of an enum from a given pattern. |
| 13920 | /// |
| 13921 | /// \param PointOfInstantiation The point of instantiation within the |
| 13922 | /// source code. |
| 13923 | /// \param Instantiation is the declaration whose definition is being |
| 13924 | /// instantiated. This will be a member enumeration of a class |
| 13925 | /// temploid specialization, or a local enumeration within a |
| 13926 | /// function temploid specialization. |
| 13927 | /// \param Pattern The templated declaration from which the instantiation |
| 13928 | /// occurs. |
| 13929 | /// \param TemplateArgs The template arguments to be substituted into |
| 13930 | /// the pattern. |
| 13931 | /// \param TSK The kind of implicit or explicit instantiation to perform. |
| 13932 | /// |
| 13933 | /// \return \c true if an error occurred, \c false otherwise. |
| 13934 | bool InstantiateEnum(SourceLocation PointOfInstantiation, |
| 13935 | EnumDecl *Instantiation, EnumDecl *Pattern, |
| 13936 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 13937 | TemplateSpecializationKind TSK); |
| 13938 | |
| 13939 | /// Instantiate the definition of a field from the given pattern. |
| 13940 | /// |
| 13941 | /// \param PointOfInstantiation The point of instantiation within the |
| 13942 | /// source code. |
| 13943 | /// \param Instantiation is the declaration whose definition is being |
| 13944 | /// instantiated. This will be a class of a class temploid |
| 13945 | /// specialization, or a local enumeration within a function temploid |
| 13946 | /// specialization. |
| 13947 | /// \param Pattern The templated declaration from which the instantiation |
| 13948 | /// occurs. |
| 13949 | /// \param TemplateArgs The template arguments to be substituted into |
| 13950 | /// the pattern. |
| 13951 | /// |
| 13952 | /// \return \c true if an error occurred, \c false otherwise. |
| 13953 | bool InstantiateInClassInitializer( |
| 13954 | SourceLocation PointOfInstantiation, FieldDecl *Instantiation, |
| 13955 | FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs); |
| 13956 | |
| 13957 | bool usesPartialOrExplicitSpecialization( |
| 13958 | SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec); |
| 13959 | |
| 13960 | bool InstantiateClassTemplateSpecialization( |
| 13961 | SourceLocation PointOfInstantiation, |
| 13962 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
| 13963 | TemplateSpecializationKind TSK, bool Complain, |
| 13964 | bool PrimaryStrictPackMatch); |
| 13965 | |
| 13966 | /// Instantiates the definitions of all of the member |
| 13967 | /// of the given class, which is an instantiation of a class template |
| 13968 | /// or a member class of a template. |
| 13969 | void |
| 13970 | InstantiateClassMembers(SourceLocation PointOfInstantiation, |
| 13971 | CXXRecordDecl *Instantiation, |
| 13972 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 13973 | TemplateSpecializationKind TSK); |
| 13974 | |
| 13975 | /// Instantiate the definitions of all of the members of the |
| 13976 | /// given class template specialization, which was named as part of an |
| 13977 | /// explicit instantiation. |
| 13978 | void InstantiateClassTemplateSpecializationMembers( |
| 13979 | SourceLocation PointOfInstantiation, |
| 13980 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
| 13981 | TemplateSpecializationKind TSK); |
| 13982 | |
| 13983 | NestedNameSpecifierLoc SubstNestedNameSpecifierLoc( |
| 13984 | NestedNameSpecifierLoc NNS, |
| 13985 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 13986 | |
| 13987 | /// Do template substitution on declaration name info. |
| 13988 | DeclarationNameInfo |
| 13989 | SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
| 13990 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 13991 | TemplateName |
| 13992 | SubstTemplateName(SourceLocation TemplateKWLoc, |
| 13993 | NestedNameSpecifierLoc &QualifierLoc, TemplateName Name, |
| 13994 | SourceLocation NameLoc, |
| 13995 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 13996 | |
| 13997 | bool SubstTypeConstraint(TemplateTypeParmDecl *Inst, const TypeConstraint *TC, |
| 13998 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 13999 | bool EvaluateConstraint); |
| 14000 | |
| 14001 | /// Determine whether we are currently performing template instantiation. |
| 14002 | bool inTemplateInstantiation() const { |
| 14003 | return CodeSynthesisContexts.size() > NonInstantiationEntries; |
| 14004 | } |
| 14005 | |
| 14006 | /// Determine whether we are currently performing constraint substitution. |
| 14007 | bool inConstraintSubstitution() const { |
| 14008 | return !CodeSynthesisContexts.empty() && |
| 14009 | CodeSynthesisContexts.back().InConstraintSubstitution; |
| 14010 | } |
| 14011 | |
| 14012 | bool inParameterMappingSubstitution() const { |
| 14013 | return !CodeSynthesisContexts.empty() && |
| 14014 | CodeSynthesisContexts.back().InParameterMappingSubstitution && |
| 14015 | !inConstraintSubstitution(); |
| 14016 | } |
| 14017 | |
| 14018 | using EntityPrinter = llvm::function_ref<void(llvm::raw_ostream &)>; |
| 14019 | |
| 14020 | /// \brief create a Requirement::SubstitutionDiagnostic with only a |
| 14021 | /// SubstitutedEntity and DiagLoc using ASTContext's allocator. |
| 14022 | concepts::Requirement::SubstitutionDiagnostic * |
| 14023 | createSubstDiagAt(SourceLocation Location, EntityPrinter Printer); |
| 14024 | |
| 14025 | ///@} |
| 14026 | |
| 14027 | // |
| 14028 | // |
| 14029 | // ------------------------------------------------------------------------- |
| 14030 | // |
| 14031 | // |
| 14032 | |
| 14033 | /// \name C++ Template Declaration Instantiation |
| 14034 | /// Implementations are in SemaTemplateInstantiateDecl.cpp |
| 14035 | ///@{ |
| 14036 | |
| 14037 | public: |
| 14038 | /// An entity for which implicit template instantiation is required. |
| 14039 | /// |
| 14040 | /// The source location associated with the declaration is the first place in |
| 14041 | /// the source code where the declaration was "used". It is not necessarily |
| 14042 | /// the point of instantiation (which will be either before or after the |
| 14043 | /// namespace-scope declaration that triggered this implicit instantiation), |
| 14044 | /// However, it is the location that diagnostics should generally refer to, |
| 14045 | /// because users will need to know what code triggered the instantiation. |
| 14046 | typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; |
| 14047 | |
| 14048 | /// The queue of implicit template instantiations that are required |
| 14049 | /// but have not yet been performed. |
| 14050 | std::deque<PendingImplicitInstantiation> PendingInstantiations; |
| 14051 | |
| 14052 | /// Queue of implicit template instantiations that cannot be performed |
| 14053 | /// eagerly. |
| 14054 | SmallVector<PendingImplicitInstantiation, 1> LateParsedInstantiations; |
| 14055 | |
| 14056 | SmallVector<SmallVector<VTableUse, 16>, 8> SavedVTableUses; |
| 14057 | SmallVector<std::deque<PendingImplicitInstantiation>, 8> |
| 14058 | SavedPendingInstantiations; |
| 14059 | |
| 14060 | /// The queue of implicit template instantiations that are required |
| 14061 | /// and must be performed within the current local scope. |
| 14062 | /// |
| 14063 | /// This queue is only used for member functions of local classes in |
| 14064 | /// templates, which must be instantiated in the same scope as their |
| 14065 | /// enclosing function, so that they can reference function-local |
| 14066 | /// types, static variables, enumerators, etc. |
| 14067 | std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; |
| 14068 | |
| 14069 | class LocalEagerInstantiationScope { |
| 14070 | public: |
| 14071 | LocalEagerInstantiationScope(Sema &S, bool AtEndOfTU) |
| 14072 | : S(S), AtEndOfTU(AtEndOfTU) { |
| 14073 | SavedPendingLocalImplicitInstantiations.swap( |
| 14074 | x&: S.PendingLocalImplicitInstantiations); |
| 14075 | } |
| 14076 | |
| 14077 | void perform() { |
| 14078 | S.PerformPendingInstantiations(/*LocalOnly=*/LocalOnly: true, |
| 14079 | /*AtEndOfTU=*/AtEndOfTU); |
| 14080 | } |
| 14081 | |
| 14082 | ~LocalEagerInstantiationScope() { |
| 14083 | assert(S.PendingLocalImplicitInstantiations.empty() && |
| 14084 | "there shouldn't be any pending local implicit instantiations" ); |
| 14085 | SavedPendingLocalImplicitInstantiations.swap( |
| 14086 | x&: S.PendingLocalImplicitInstantiations); |
| 14087 | } |
| 14088 | |
| 14089 | LocalEagerInstantiationScope(const LocalEagerInstantiationScope &) = delete; |
| 14090 | LocalEagerInstantiationScope & |
| 14091 | operator=(const LocalEagerInstantiationScope &) = delete; |
| 14092 | |
| 14093 | private: |
| 14094 | Sema &S; |
| 14095 | bool AtEndOfTU; |
| 14096 | std::deque<PendingImplicitInstantiation> |
| 14097 | SavedPendingLocalImplicitInstantiations; |
| 14098 | }; |
| 14099 | |
| 14100 | /// Records and restores the CurFPFeatures state on entry/exit of compound |
| 14101 | /// statements. |
| 14102 | class FPFeaturesStateRAII { |
| 14103 | public: |
| 14104 | FPFeaturesStateRAII(Sema &S); |
| 14105 | ~FPFeaturesStateRAII(); |
| 14106 | FPOptionsOverride getOverrides() { return OldOverrides; } |
| 14107 | |
| 14108 | private: |
| 14109 | Sema &S; |
| 14110 | FPOptions OldFPFeaturesState; |
| 14111 | FPOptionsOverride OldOverrides; |
| 14112 | LangOptions::FPEvalMethodKind OldEvalMethod; |
| 14113 | SourceLocation OldFPPragmaLocation; |
| 14114 | }; |
| 14115 | |
| 14116 | class GlobalEagerInstantiationScope { |
| 14117 | public: |
| 14118 | GlobalEagerInstantiationScope(Sema &S, bool Enabled, bool AtEndOfTU) |
| 14119 | : S(S), Enabled(Enabled), AtEndOfTU(AtEndOfTU) { |
| 14120 | if (!Enabled) |
| 14121 | return; |
| 14122 | |
| 14123 | S.SavedPendingInstantiations.emplace_back(); |
| 14124 | S.SavedPendingInstantiations.back().swap(x&: S.PendingInstantiations); |
| 14125 | |
| 14126 | S.SavedVTableUses.emplace_back(); |
| 14127 | S.SavedVTableUses.back().swap(RHS&: S.VTableUses); |
| 14128 | } |
| 14129 | |
| 14130 | void perform() { |
| 14131 | if (Enabled) { |
| 14132 | S.DefineUsedVTables(); |
| 14133 | S.PerformPendingInstantiations(/*LocalOnly=*/LocalOnly: false, |
| 14134 | /*AtEndOfTU=*/AtEndOfTU); |
| 14135 | } |
| 14136 | } |
| 14137 | |
| 14138 | ~GlobalEagerInstantiationScope() { |
| 14139 | if (!Enabled) |
| 14140 | return; |
| 14141 | |
| 14142 | // Restore the set of pending vtables. |
| 14143 | assert(S.VTableUses.empty() && |
| 14144 | "VTableUses should be empty before it is discarded." ); |
| 14145 | S.VTableUses.swap(RHS&: S.SavedVTableUses.back()); |
| 14146 | S.SavedVTableUses.pop_back(); |
| 14147 | |
| 14148 | // Restore the set of pending implicit instantiations. |
| 14149 | if ((S.TUKind != TU_Prefix || !S.LangOpts.PCHInstantiateTemplates) && |
| 14150 | AtEndOfTU) { |
| 14151 | assert(S.PendingInstantiations.empty() && |
| 14152 | "PendingInstantiations should be empty before it is discarded." ); |
| 14153 | S.PendingInstantiations.swap(x&: S.SavedPendingInstantiations.back()); |
| 14154 | S.SavedPendingInstantiations.pop_back(); |
| 14155 | } else { |
| 14156 | // Template instantiations in the PCH may be delayed until the TU. |
| 14157 | S.PendingInstantiations.swap(x&: S.SavedPendingInstantiations.back()); |
| 14158 | S.PendingInstantiations.insert( |
| 14159 | position: S.PendingInstantiations.end(), |
| 14160 | first: S.SavedPendingInstantiations.back().begin(), |
| 14161 | last: S.SavedPendingInstantiations.back().end()); |
| 14162 | S.SavedPendingInstantiations.pop_back(); |
| 14163 | } |
| 14164 | } |
| 14165 | |
| 14166 | GlobalEagerInstantiationScope(const GlobalEagerInstantiationScope &) = |
| 14167 | delete; |
| 14168 | GlobalEagerInstantiationScope & |
| 14169 | operator=(const GlobalEagerInstantiationScope &) = delete; |
| 14170 | |
| 14171 | private: |
| 14172 | Sema &S; |
| 14173 | bool Enabled; |
| 14174 | bool AtEndOfTU; |
| 14175 | }; |
| 14176 | |
| 14177 | ExplicitSpecifier instantiateExplicitSpecifier( |
| 14178 | const MultiLevelTemplateArgumentList &TemplateArgs, ExplicitSpecifier ES); |
| 14179 | |
| 14180 | struct LateInstantiatedAttribute { |
| 14181 | const Attr *TmplAttr; |
| 14182 | LocalInstantiationScope *Scope; |
| 14183 | Decl *NewDecl; |
| 14184 | |
| 14185 | LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S, |
| 14186 | Decl *D) |
| 14187 | : TmplAttr(A), Scope(S), NewDecl(D) {} |
| 14188 | }; |
| 14189 | typedef SmallVector<LateInstantiatedAttribute, 1> LateInstantiatedAttrVec; |
| 14190 | |
| 14191 | void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, |
| 14192 | const Decl *Pattern, Decl *Inst, |
| 14193 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
| 14194 | LocalInstantiationScope *OuterMostScope = nullptr); |
| 14195 | |
| 14196 | /// Update instantiation attributes after template was late parsed. |
| 14197 | /// |
| 14198 | /// Some attributes are evaluated based on the body of template. If it is |
| 14199 | /// late parsed, such attributes cannot be evaluated when declaration is |
| 14200 | /// instantiated. This function is used to update instantiation attributes |
| 14201 | /// when template definition is ready. |
| 14202 | void updateAttrsForLateParsedTemplate(const Decl *Pattern, Decl *Inst); |
| 14203 | |
| 14204 | void |
| 14205 | InstantiateAttrsForDecl(const MultiLevelTemplateArgumentList &TemplateArgs, |
| 14206 | const Decl *Pattern, Decl *Inst, |
| 14207 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
| 14208 | LocalInstantiationScope *OuterMostScope = nullptr); |
| 14209 | |
| 14210 | /// In the MS ABI, we need to instantiate default arguments of dllexported |
| 14211 | /// default constructors along with the constructor definition. This allows IR |
| 14212 | /// gen to emit a constructor closure which calls the default constructor with |
| 14213 | /// its default arguments. |
| 14214 | void InstantiateDefaultCtorDefaultArgs(CXXConstructorDecl *Ctor); |
| 14215 | |
| 14216 | bool InstantiateDefaultArgument(SourceLocation CallLoc, FunctionDecl *FD, |
| 14217 | ParmVarDecl *Param); |
| 14218 | void InstantiateExceptionSpec(SourceLocation PointOfInstantiation, |
| 14219 | FunctionDecl *Function); |
| 14220 | |
| 14221 | /// Instantiate (or find existing instantiation of) a function template with a |
| 14222 | /// given set of template arguments. |
| 14223 | /// |
| 14224 | /// Usually this should not be used, and template argument deduction should be |
| 14225 | /// used in its place. |
| 14226 | FunctionDecl *InstantiateFunctionDeclaration( |
| 14227 | FunctionTemplateDecl *FTD, const TemplateArgumentList *Args, |
| 14228 | SourceLocation Loc, |
| 14229 | CodeSynthesisContext::SynthesisKind CSC = |
| 14230 | CodeSynthesisContext::ExplicitTemplateArgumentSubstitution); |
| 14231 | |
| 14232 | /// Instantiate the definition of the given function from its |
| 14233 | /// template. |
| 14234 | /// |
| 14235 | /// \param PointOfInstantiation the point at which the instantiation was |
| 14236 | /// required. Note that this is not precisely a "point of instantiation" |
| 14237 | /// for the function, but it's close. |
| 14238 | /// |
| 14239 | /// \param Function the already-instantiated declaration of a |
| 14240 | /// function template specialization or member function of a class template |
| 14241 | /// specialization. |
| 14242 | /// |
| 14243 | /// \param Recursive if true, recursively instantiates any functions that |
| 14244 | /// are required by this instantiation. |
| 14245 | /// |
| 14246 | /// \param DefinitionRequired if true, then we are performing an explicit |
| 14247 | /// instantiation where the body of the function is required. Complain if |
| 14248 | /// there is no such body. |
| 14249 | void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, |
| 14250 | FunctionDecl *Function, |
| 14251 | bool Recursive = false, |
| 14252 | bool DefinitionRequired = false, |
| 14253 | bool AtEndOfTU = false); |
| 14254 | VarTemplateSpecializationDecl *BuildVarTemplateInstantiation( |
| 14255 | VarTemplateDecl *VarTemplate, VarDecl *FromVar, |
| 14256 | const TemplateArgumentList *PartialSpecArgs, |
| 14257 | SmallVectorImpl<TemplateArgument> &Converted, |
| 14258 | SourceLocation PointOfInstantiation, |
| 14259 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
| 14260 | LocalInstantiationScope *StartingScope = nullptr); |
| 14261 | |
| 14262 | /// Instantiates a variable template specialization by completing it |
| 14263 | /// with appropriate type information and initializer. |
| 14264 | VarTemplateSpecializationDecl *CompleteVarTemplateSpecializationDecl( |
| 14265 | VarTemplateSpecializationDecl *VarSpec, VarDecl *PatternDecl, |
| 14266 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 14267 | |
| 14268 | /// BuildVariableInstantiation - Used after a new variable has been created. |
| 14269 | /// Sets basic variable data and decides whether to postpone the |
| 14270 | /// variable instantiation. |
| 14271 | void |
| 14272 | BuildVariableInstantiation(VarDecl *NewVar, VarDecl *OldVar, |
| 14273 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 14274 | LateInstantiatedAttrVec *LateAttrs, |
| 14275 | DeclContext *Owner, |
| 14276 | LocalInstantiationScope *StartingScope, |
| 14277 | bool InstantiatingVarTemplate = false, |
| 14278 | VarTemplateSpecializationDecl *PrevVTSD = nullptr); |
| 14279 | |
| 14280 | /// Instantiate the initializer of a variable. |
| 14281 | void InstantiateVariableInitializer( |
| 14282 | VarDecl *Var, VarDecl *OldVar, |
| 14283 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 14284 | |
| 14285 | /// Instantiate the definition of the given variable from its |
| 14286 | /// template. |
| 14287 | /// |
| 14288 | /// \param PointOfInstantiation the point at which the instantiation was |
| 14289 | /// required. Note that this is not precisely a "point of instantiation" |
| 14290 | /// for the variable, but it's close. |
| 14291 | /// |
| 14292 | /// \param Var the already-instantiated declaration of a templated variable. |
| 14293 | /// |
| 14294 | /// \param Recursive if true, recursively instantiates any functions that |
| 14295 | /// are required by this instantiation. |
| 14296 | /// |
| 14297 | /// \param DefinitionRequired if true, then we are performing an explicit |
| 14298 | /// instantiation where a definition of the variable is required. Complain |
| 14299 | /// if there is no such definition. |
| 14300 | void InstantiateVariableDefinition(SourceLocation PointOfInstantiation, |
| 14301 | VarDecl *Var, bool Recursive = false, |
| 14302 | bool DefinitionRequired = false, |
| 14303 | bool AtEndOfTU = false); |
| 14304 | |
| 14305 | void InstantiateMemInitializers( |
| 14306 | CXXConstructorDecl *New, const CXXConstructorDecl *Tmpl, |
| 14307 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 14308 | |
| 14309 | /// Find the instantiation of the given declaration within the |
| 14310 | /// current instantiation. |
| 14311 | /// |
| 14312 | /// This routine is intended to be used when \p D is a declaration |
| 14313 | /// referenced from within a template, that needs to mapped into the |
| 14314 | /// corresponding declaration within an instantiation. For example, |
| 14315 | /// given: |
| 14316 | /// |
| 14317 | /// \code |
| 14318 | /// template<typename T> |
| 14319 | /// struct X { |
| 14320 | /// enum Kind { |
| 14321 | /// KnownValue = sizeof(T) |
| 14322 | /// }; |
| 14323 | /// |
| 14324 | /// bool getKind() const { return KnownValue; } |
| 14325 | /// }; |
| 14326 | /// |
| 14327 | /// template struct X<int>; |
| 14328 | /// \endcode |
| 14329 | /// |
| 14330 | /// In the instantiation of X<int>::getKind(), we need to map the \p |
| 14331 | /// EnumConstantDecl for \p KnownValue (which refers to |
| 14332 | /// X<T>::<Kind>::KnownValue) to its instantiation |
| 14333 | /// (X<int>::<Kind>::KnownValue). |
| 14334 | /// \p FindInstantiatedDecl performs this mapping from within the |
| 14335 | /// instantiation of X<int>. |
| 14336 | NamedDecl * |
| 14337 | FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, |
| 14338 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 14339 | bool FindingInstantiatedContext = false); |
| 14340 | |
| 14341 | /// Finds the instantiation of the given declaration context |
| 14342 | /// within the current instantiation. |
| 14343 | /// |
| 14344 | /// \returns NULL if there was an error |
| 14345 | DeclContext * |
| 14346 | FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, |
| 14347 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 14348 | |
| 14349 | Decl *SubstDecl(Decl *D, DeclContext *Owner, |
| 14350 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 14351 | |
| 14352 | /// Substitute the name and return type of a defaulted 'operator<=>' to form |
| 14353 | /// an implicit 'operator=='. |
| 14354 | FunctionDecl *SubstSpaceshipAsEqualEqual(CXXRecordDecl *RD, |
| 14355 | FunctionDecl *Spaceship); |
| 14356 | |
| 14357 | /// Performs template instantiation for all implicit template |
| 14358 | /// instantiations we have seen until this point. |
| 14359 | void PerformPendingInstantiations(bool LocalOnly = false, |
| 14360 | bool AtEndOfTU = true); |
| 14361 | |
| 14362 | TemplateParameterList * |
| 14363 | SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner, |
| 14364 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 14365 | bool EvaluateConstraints = true); |
| 14366 | |
| 14367 | void PerformDependentDiagnostics( |
| 14368 | const DeclContext *Pattern, |
| 14369 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 14370 | |
| 14371 | private: |
| 14372 | /// Introduce the instantiated local variables into the local |
| 14373 | /// instantiation scope. |
| 14374 | void addInstantiatedLocalVarsToScope(FunctionDecl *Function, |
| 14375 | const FunctionDecl *PatternDecl, |
| 14376 | LocalInstantiationScope &Scope); |
| 14377 | /// Introduce the instantiated function parameters into the local |
| 14378 | /// instantiation scope, and set the parameter names to those used |
| 14379 | /// in the template. |
| 14380 | bool addInstantiatedParametersToScope( |
| 14381 | FunctionDecl *Function, const FunctionDecl *PatternDecl, |
| 14382 | LocalInstantiationScope &Scope, |
| 14383 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 14384 | |
| 14385 | /// Introduce the instantiated captures of the lambda into the local |
| 14386 | /// instantiation scope. |
| 14387 | bool addInstantiatedCapturesToScope( |
| 14388 | FunctionDecl *Function, const FunctionDecl *PatternDecl, |
| 14389 | LocalInstantiationScope &Scope, |
| 14390 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 14391 | |
| 14392 | int ParsingClassDepth = 0; |
| 14393 | |
| 14394 | class SavePendingParsedClassStateRAII { |
| 14395 | public: |
| 14396 | SavePendingParsedClassStateRAII(Sema &S) : S(S) { swapSavedState(); } |
| 14397 | |
| 14398 | ~SavePendingParsedClassStateRAII() { |
| 14399 | assert(S.DelayedOverridingExceptionSpecChecks.empty() && |
| 14400 | "there shouldn't be any pending delayed exception spec checks" ); |
| 14401 | assert(S.DelayedEquivalentExceptionSpecChecks.empty() && |
| 14402 | "there shouldn't be any pending delayed exception spec checks" ); |
| 14403 | swapSavedState(); |
| 14404 | } |
| 14405 | |
| 14406 | SavePendingParsedClassStateRAII(const SavePendingParsedClassStateRAII &) = |
| 14407 | delete; |
| 14408 | SavePendingParsedClassStateRAII & |
| 14409 | operator=(const SavePendingParsedClassStateRAII &) = delete; |
| 14410 | |
| 14411 | private: |
| 14412 | Sema &S; |
| 14413 | decltype(DelayedOverridingExceptionSpecChecks) |
| 14414 | SavedOverridingExceptionSpecChecks; |
| 14415 | decltype(DelayedEquivalentExceptionSpecChecks) |
| 14416 | SavedEquivalentExceptionSpecChecks; |
| 14417 | |
| 14418 | void swapSavedState() { |
| 14419 | SavedOverridingExceptionSpecChecks.swap( |
| 14420 | RHS&: S.DelayedOverridingExceptionSpecChecks); |
| 14421 | SavedEquivalentExceptionSpecChecks.swap( |
| 14422 | RHS&: S.DelayedEquivalentExceptionSpecChecks); |
| 14423 | } |
| 14424 | }; |
| 14425 | |
| 14426 | ///@} |
| 14427 | |
| 14428 | // |
| 14429 | // |
| 14430 | // ------------------------------------------------------------------------- |
| 14431 | // |
| 14432 | // |
| 14433 | |
| 14434 | /// \name C++ Variadic Templates |
| 14435 | /// Implementations are in SemaTemplateVariadic.cpp |
| 14436 | ///@{ |
| 14437 | |
| 14438 | public: |
| 14439 | /// Determine whether an unexpanded parameter pack might be permitted in this |
| 14440 | /// location. Useful for error recovery. |
| 14441 | bool isUnexpandedParameterPackPermitted(); |
| 14442 | |
| 14443 | /// The context in which an unexpanded parameter pack is |
| 14444 | /// being diagnosed. |
| 14445 | /// |
| 14446 | /// Note that the values of this enumeration line up with the first |
| 14447 | /// argument to the \c err_unexpanded_parameter_pack diagnostic. |
| 14448 | enum UnexpandedParameterPackContext { |
| 14449 | /// An arbitrary expression. |
| 14450 | UPPC_Expression = 0, |
| 14451 | |
| 14452 | /// The base type of a class type. |
| 14453 | UPPC_BaseType, |
| 14454 | |
| 14455 | /// The type of an arbitrary declaration. |
| 14456 | UPPC_DeclarationType, |
| 14457 | |
| 14458 | /// The type of a data member. |
| 14459 | UPPC_DataMemberType, |
| 14460 | |
| 14461 | /// The size of a bit-field. |
| 14462 | UPPC_BitFieldWidth, |
| 14463 | |
| 14464 | /// The expression in a static assertion. |
| 14465 | UPPC_StaticAssertExpression, |
| 14466 | |
| 14467 | /// The fixed underlying type of an enumeration. |
| 14468 | UPPC_FixedUnderlyingType, |
| 14469 | |
| 14470 | /// The enumerator value. |
| 14471 | UPPC_EnumeratorValue, |
| 14472 | |
| 14473 | /// A using declaration. |
| 14474 | UPPC_UsingDeclaration, |
| 14475 | |
| 14476 | /// A friend declaration. |
| 14477 | UPPC_FriendDeclaration, |
| 14478 | |
| 14479 | /// A declaration qualifier. |
| 14480 | UPPC_DeclarationQualifier, |
| 14481 | |
| 14482 | /// An initializer. |
| 14483 | UPPC_Initializer, |
| 14484 | |
| 14485 | /// A default argument. |
| 14486 | UPPC_DefaultArgument, |
| 14487 | |
| 14488 | /// The type of a non-type template parameter. |
| 14489 | UPPC_NonTypeTemplateParameterType, |
| 14490 | |
| 14491 | /// The type of an exception. |
| 14492 | UPPC_ExceptionType, |
| 14493 | |
| 14494 | /// Explicit specialization. |
| 14495 | UPPC_ExplicitSpecialization, |
| 14496 | |
| 14497 | /// Partial specialization. |
| 14498 | UPPC_PartialSpecialization, |
| 14499 | |
| 14500 | /// Microsoft __if_exists. |
| 14501 | UPPC_IfExists, |
| 14502 | |
| 14503 | /// Microsoft __if_not_exists. |
| 14504 | UPPC_IfNotExists, |
| 14505 | |
| 14506 | /// Lambda expression. |
| 14507 | UPPC_Lambda, |
| 14508 | |
| 14509 | /// Block expression. |
| 14510 | UPPC_Block, |
| 14511 | |
| 14512 | /// A type constraint. |
| 14513 | UPPC_TypeConstraint, |
| 14514 | |
| 14515 | // A requirement in a requires-expression. |
| 14516 | UPPC_Requirement, |
| 14517 | |
| 14518 | // A requires-clause. |
| 14519 | UPPC_RequiresClause, |
| 14520 | }; |
| 14521 | |
| 14522 | /// Diagnose unexpanded parameter packs. |
| 14523 | /// |
| 14524 | /// \param Loc The location at which we should emit the diagnostic. |
| 14525 | /// |
| 14526 | /// \param UPPC The context in which we are diagnosing unexpanded |
| 14527 | /// parameter packs. |
| 14528 | /// |
| 14529 | /// \param Unexpanded the set of unexpanded parameter packs. |
| 14530 | /// |
| 14531 | /// \returns true if an error occurred, false otherwise. |
| 14532 | bool DiagnoseUnexpandedParameterPacks( |
| 14533 | SourceLocation Loc, UnexpandedParameterPackContext UPPC, |
| 14534 | ArrayRef<UnexpandedParameterPack> Unexpanded); |
| 14535 | |
| 14536 | /// If the given type contains an unexpanded parameter pack, |
| 14537 | /// diagnose the error. |
| 14538 | /// |
| 14539 | /// \param Loc The source location where a diagnostc should be emitted. |
| 14540 | /// |
| 14541 | /// \param T The type that is being checked for unexpanded parameter |
| 14542 | /// packs. |
| 14543 | /// |
| 14544 | /// \returns true if an error occurred, false otherwise. |
| 14545 | bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, |
| 14546 | UnexpandedParameterPackContext UPPC); |
| 14547 | |
| 14548 | /// If the given expression contains an unexpanded parameter |
| 14549 | /// pack, diagnose the error. |
| 14550 | /// |
| 14551 | /// \param E The expression that is being checked for unexpanded |
| 14552 | /// parameter packs. |
| 14553 | /// |
| 14554 | /// \returns true if an error occurred, false otherwise. |
| 14555 | bool DiagnoseUnexpandedParameterPack( |
| 14556 | Expr *E, UnexpandedParameterPackContext UPPC = UPPC_Expression); |
| 14557 | |
| 14558 | /// If the given requirees-expression contains an unexpanded reference to one |
| 14559 | /// of its own parameter packs, diagnose the error. |
| 14560 | /// |
| 14561 | /// \param RE The requiress-expression that is being checked for unexpanded |
| 14562 | /// parameter packs. |
| 14563 | /// |
| 14564 | /// \returns true if an error occurred, false otherwise. |
| 14565 | bool DiagnoseUnexpandedParameterPackInRequiresExpr(RequiresExpr *RE); |
| 14566 | |
| 14567 | /// If the given nested-name-specifier contains an unexpanded |
| 14568 | /// parameter pack, diagnose the error. |
| 14569 | /// |
| 14570 | /// \param SS The nested-name-specifier that is being checked for |
| 14571 | /// unexpanded parameter packs. |
| 14572 | /// |
| 14573 | /// \returns true if an error occurred, false otherwise. |
| 14574 | bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, |
| 14575 | UnexpandedParameterPackContext UPPC); |
| 14576 | |
| 14577 | /// If the given name contains an unexpanded parameter pack, |
| 14578 | /// diagnose the error. |
| 14579 | /// |
| 14580 | /// \param NameInfo The name (with source location information) that |
| 14581 | /// is being checked for unexpanded parameter packs. |
| 14582 | /// |
| 14583 | /// \returns true if an error occurred, false otherwise. |
| 14584 | bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, |
| 14585 | UnexpandedParameterPackContext UPPC); |
| 14586 | |
| 14587 | /// If the given template name contains an unexpanded parameter pack, |
| 14588 | /// diagnose the error. |
| 14589 | /// |
| 14590 | /// \param Loc The location of the template name. |
| 14591 | /// |
| 14592 | /// \param Template The template name that is being checked for unexpanded |
| 14593 | /// parameter packs. |
| 14594 | /// |
| 14595 | /// \returns true if an error occurred, false otherwise. |
| 14596 | bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, |
| 14597 | TemplateName Template, |
| 14598 | UnexpandedParameterPackContext UPPC); |
| 14599 | |
| 14600 | /// If the given template argument contains an unexpanded parameter |
| 14601 | /// pack, diagnose the error. |
| 14602 | /// |
| 14603 | /// \param Arg The template argument that is being checked for unexpanded |
| 14604 | /// parameter packs. |
| 14605 | /// |
| 14606 | /// \returns true if an error occurred, false otherwise. |
| 14607 | bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, |
| 14608 | UnexpandedParameterPackContext UPPC); |
| 14609 | |
| 14610 | /// Collect the set of unexpanded parameter packs within the given |
| 14611 | /// template argument. |
| 14612 | /// |
| 14613 | /// \param Arg The template argument that will be traversed to find |
| 14614 | /// unexpanded parameter packs. |
| 14615 | void collectUnexpandedParameterPacks( |
| 14616 | TemplateArgument Arg, |
| 14617 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
| 14618 | |
| 14619 | /// Collect the set of unexpanded parameter packs within the given |
| 14620 | /// template argument. |
| 14621 | /// |
| 14622 | /// \param Arg The template argument that will be traversed to find |
| 14623 | /// unexpanded parameter packs. |
| 14624 | void collectUnexpandedParameterPacks( |
| 14625 | TemplateArgumentLoc Arg, |
| 14626 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
| 14627 | |
| 14628 | /// Collect the set of unexpanded parameter packs within the given |
| 14629 | /// type. |
| 14630 | /// |
| 14631 | /// \param T The type that will be traversed to find |
| 14632 | /// unexpanded parameter packs. |
| 14633 | void collectUnexpandedParameterPacks( |
| 14634 | QualType T, SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
| 14635 | |
| 14636 | /// Collect the set of unexpanded parameter packs within the given |
| 14637 | /// type. |
| 14638 | /// |
| 14639 | /// \param TL The type that will be traversed to find |
| 14640 | /// unexpanded parameter packs. |
| 14641 | void collectUnexpandedParameterPacks( |
| 14642 | TypeLoc TL, SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
| 14643 | |
| 14644 | /// Collect the set of unexpanded parameter packs within the given |
| 14645 | /// nested-name-specifier. |
| 14646 | /// |
| 14647 | /// \param NNS The nested-name-specifier that will be traversed to find |
| 14648 | /// unexpanded parameter packs. |
| 14649 | void collectUnexpandedParameterPacks( |
| 14650 | NestedNameSpecifierLoc NNS, |
| 14651 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
| 14652 | |
| 14653 | /// Collect the set of unexpanded parameter packs within the given |
| 14654 | /// name. |
| 14655 | /// |
| 14656 | /// \param NameInfo The name that will be traversed to find |
| 14657 | /// unexpanded parameter packs. |
| 14658 | void collectUnexpandedParameterPacks( |
| 14659 | const DeclarationNameInfo &NameInfo, |
| 14660 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
| 14661 | |
| 14662 | /// Collect the set of unexpanded parameter packs within the given |
| 14663 | /// expression. |
| 14664 | static void collectUnexpandedParameterPacks( |
| 14665 | Expr *E, SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
| 14666 | |
| 14667 | /// Invoked when parsing a template argument. |
| 14668 | /// |
| 14669 | /// \param Arg the template argument, which may already be invalid. |
| 14670 | /// |
| 14671 | /// If it is followed by ellipsis, this function is called before |
| 14672 | /// `ActOnPackExpansion`. |
| 14673 | ParsedTemplateArgument |
| 14674 | ActOnTemplateTemplateArgument(const ParsedTemplateArgument &Arg); |
| 14675 | |
| 14676 | /// Invoked when parsing a template argument followed by an |
| 14677 | /// ellipsis, which creates a pack expansion. |
| 14678 | /// |
| 14679 | /// \param Arg The template argument preceding the ellipsis, which |
| 14680 | /// may already be invalid. |
| 14681 | /// |
| 14682 | /// \param EllipsisLoc The location of the ellipsis. |
| 14683 | ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, |
| 14684 | SourceLocation EllipsisLoc); |
| 14685 | |
| 14686 | /// Invoked when parsing a type followed by an ellipsis, which |
| 14687 | /// creates a pack expansion. |
| 14688 | /// |
| 14689 | /// \param Type The type preceding the ellipsis, which will become |
| 14690 | /// the pattern of the pack expansion. |
| 14691 | /// |
| 14692 | /// \param EllipsisLoc The location of the ellipsis. |
| 14693 | TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc); |
| 14694 | |
| 14695 | /// Construct a pack expansion type from the pattern of the pack |
| 14696 | /// expansion. |
| 14697 | TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern, |
| 14698 | SourceLocation EllipsisLoc, |
| 14699 | UnsignedOrNone NumExpansions); |
| 14700 | |
| 14701 | /// Construct a pack expansion type from the pattern of the pack |
| 14702 | /// expansion. |
| 14703 | QualType CheckPackExpansion(QualType Pattern, SourceRange PatternRange, |
| 14704 | SourceLocation EllipsisLoc, |
| 14705 | UnsignedOrNone NumExpansions); |
| 14706 | |
| 14707 | /// Invoked when parsing an expression followed by an ellipsis, which |
| 14708 | /// creates a pack expansion. |
| 14709 | /// |
| 14710 | /// \param Pattern The expression preceding the ellipsis, which will become |
| 14711 | /// the pattern of the pack expansion. |
| 14712 | /// |
| 14713 | /// \param EllipsisLoc The location of the ellipsis. |
| 14714 | ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc); |
| 14715 | |
| 14716 | /// Invoked when parsing an expression followed by an ellipsis, which |
| 14717 | /// creates a pack expansion. |
| 14718 | /// |
| 14719 | /// \param Pattern The expression preceding the ellipsis, which will become |
| 14720 | /// the pattern of the pack expansion. |
| 14721 | /// |
| 14722 | /// \param EllipsisLoc The location of the ellipsis. |
| 14723 | ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
| 14724 | UnsignedOrNone NumExpansions); |
| 14725 | |
| 14726 | /// Determine whether we could expand a pack expansion with the |
| 14727 | /// given set of parameter packs into separate arguments by repeatedly |
| 14728 | /// transforming the pattern. |
| 14729 | /// |
| 14730 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 14731 | /// pack expansion. |
| 14732 | /// |
| 14733 | /// \param PatternRange The source range that covers the entire pattern of |
| 14734 | /// the pack expansion. |
| 14735 | /// |
| 14736 | /// \param Unexpanded The set of unexpanded parameter packs within the |
| 14737 | /// pattern. |
| 14738 | /// |
| 14739 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 14740 | /// expand the corresponding pack expansions into separate arguments. When |
| 14741 | /// set, \c NumExpansions must also be set. |
| 14742 | /// |
| 14743 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 14744 | /// pack expansion after all of the expanded arguments. This is used |
| 14745 | /// when extending explicitly-specified template argument packs per |
| 14746 | /// C++0x [temp.arg.explicit]p9. |
| 14747 | /// |
| 14748 | /// \param NumExpansions The number of separate arguments that will be in |
| 14749 | /// the expanded form of the corresponding pack expansion. This is both an |
| 14750 | /// input and an output parameter, which can be set by the caller if the |
| 14751 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 14752 | /// and will be set by the callee when the number of expansions is known. |
| 14753 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 14754 | /// set this value in other cases. |
| 14755 | /// |
| 14756 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 14757 | /// are to be instantiated with arguments of different lengths), false |
| 14758 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
| 14759 | /// must be set. |
| 14760 | bool CheckParameterPacksForExpansion( |
| 14761 | SourceLocation EllipsisLoc, SourceRange PatternRange, |
| 14762 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
| 14763 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 14764 | bool FailOnPackProducingTemplates, bool &ShouldExpand, |
| 14765 | bool &RetainExpansion, UnsignedOrNone &NumExpansions, |
| 14766 | bool Diagnose = true); |
| 14767 | |
| 14768 | /// Determine the number of arguments in the given pack expansion |
| 14769 | /// type. |
| 14770 | /// |
| 14771 | /// This routine assumes that the number of arguments in the expansion is |
| 14772 | /// consistent across all of the unexpanded parameter packs in its pattern. |
| 14773 | /// |
| 14774 | /// Returns an empty Optional if the type can't be expanded. |
| 14775 | UnsignedOrNone getNumArgumentsInExpansion( |
| 14776 | QualType T, const MultiLevelTemplateArgumentList &TemplateArgs); |
| 14777 | |
| 14778 | UnsignedOrNone getNumArgumentsInExpansionFromUnexpanded( |
| 14779 | llvm::ArrayRef<UnexpandedParameterPack> Unexpanded, |
| 14780 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 14781 | |
| 14782 | /// Determine whether the given declarator contains any unexpanded |
| 14783 | /// parameter packs. |
| 14784 | /// |
| 14785 | /// This routine is used by the parser to disambiguate function declarators |
| 14786 | /// with an ellipsis prior to the ')', e.g., |
| 14787 | /// |
| 14788 | /// \code |
| 14789 | /// void f(T...); |
| 14790 | /// \endcode |
| 14791 | /// |
| 14792 | /// To determine whether we have an (unnamed) function parameter pack or |
| 14793 | /// a variadic function. |
| 14794 | /// |
| 14795 | /// \returns true if the declarator contains any unexpanded parameter packs, |
| 14796 | /// false otherwise. |
| 14797 | bool containsUnexpandedParameterPacks(Declarator &D); |
| 14798 | |
| 14799 | /// Returns the pattern of the pack expansion for a template argument. |
| 14800 | /// |
| 14801 | /// \param OrigLoc The template argument to expand. |
| 14802 | /// |
| 14803 | /// \param Ellipsis Will be set to the location of the ellipsis. |
| 14804 | /// |
| 14805 | /// \param NumExpansions Will be set to the number of expansions that will |
| 14806 | /// be generated from this pack expansion, if known a priori. |
| 14807 | TemplateArgumentLoc |
| 14808 | getTemplateArgumentPackExpansionPattern(TemplateArgumentLoc OrigLoc, |
| 14809 | SourceLocation &Ellipsis, |
| 14810 | UnsignedOrNone &NumExpansions) const; |
| 14811 | |
| 14812 | /// Given a template argument that contains an unexpanded parameter pack, but |
| 14813 | /// which has already been substituted, attempt to determine the number of |
| 14814 | /// elements that will be produced once this argument is fully-expanded. |
| 14815 | /// |
| 14816 | /// This is intended for use when transforming 'sizeof...(Arg)' in order to |
| 14817 | /// avoid actually expanding the pack where possible. |
| 14818 | UnsignedOrNone getFullyPackExpandedSize(TemplateArgument Arg); |
| 14819 | |
| 14820 | /// Called when an expression computing the size of a parameter pack |
| 14821 | /// is parsed. |
| 14822 | /// |
| 14823 | /// \code |
| 14824 | /// template<typename ...Types> struct count { |
| 14825 | /// static const unsigned value = sizeof...(Types); |
| 14826 | /// }; |
| 14827 | /// \endcode |
| 14828 | /// |
| 14829 | // |
| 14830 | /// \param OpLoc The location of the "sizeof" keyword. |
| 14831 | /// \param Name The name of the parameter pack whose size will be determined. |
| 14832 | /// \param NameLoc The source location of the name of the parameter pack. |
| 14833 | /// \param RParenLoc The location of the closing parentheses. |
| 14834 | ExprResult ActOnSizeofParameterPackExpr(Scope *S, SourceLocation OpLoc, |
| 14835 | IdentifierInfo &Name, |
| 14836 | SourceLocation NameLoc, |
| 14837 | SourceLocation RParenLoc); |
| 14838 | |
| 14839 | ExprResult ActOnPackIndexingExpr(Scope *S, Expr *PackExpression, |
| 14840 | SourceLocation EllipsisLoc, |
| 14841 | SourceLocation LSquareLoc, Expr *IndexExpr, |
| 14842 | SourceLocation RSquareLoc); |
| 14843 | |
| 14844 | ExprResult BuildPackIndexingExpr(Expr *PackExpression, |
| 14845 | SourceLocation EllipsisLoc, Expr *IndexExpr, |
| 14846 | SourceLocation RSquareLoc, |
| 14847 | ArrayRef<Expr *> ExpandedExprs = {}, |
| 14848 | bool FullySubstituted = false); |
| 14849 | |
| 14850 | /// Handle a C++1z fold-expression: ( expr op ... op expr ). |
| 14851 | ExprResult ActOnCXXFoldExpr(Scope *S, SourceLocation LParenLoc, Expr *LHS, |
| 14852 | tok::TokenKind Operator, |
| 14853 | SourceLocation EllipsisLoc, Expr *RHS, |
| 14854 | SourceLocation RParenLoc); |
| 14855 | ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, |
| 14856 | SourceLocation LParenLoc, Expr *LHS, |
| 14857 | BinaryOperatorKind Operator, |
| 14858 | SourceLocation EllipsisLoc, Expr *RHS, |
| 14859 | SourceLocation RParenLoc, |
| 14860 | UnsignedOrNone NumExpansions); |
| 14861 | ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |
| 14862 | BinaryOperatorKind Operator); |
| 14863 | |
| 14864 | ///@} |
| 14865 | |
| 14866 | // |
| 14867 | // |
| 14868 | // ------------------------------------------------------------------------- |
| 14869 | // |
| 14870 | // |
| 14871 | |
| 14872 | /// \name Constraints and Concepts |
| 14873 | /// Implementations are in SemaConcept.cpp |
| 14874 | ///@{ |
| 14875 | |
| 14876 | public: |
| 14877 | ExprResult ActOnCXXReflectExpr(SourceLocation OpLoc, TypeSourceInfo *TSI); |
| 14878 | |
| 14879 | ExprResult BuildCXXReflectExpr(SourceLocation OperatorLoc, |
| 14880 | TypeSourceInfo *TSI); |
| 14881 | |
| 14882 | public: |
| 14883 | void PushSatisfactionStackEntry(const NamedDecl *D, |
| 14884 | const llvm::FoldingSetNodeID &ID) { |
| 14885 | const NamedDecl *Can = cast<NamedDecl>(Val: D->getCanonicalDecl()); |
| 14886 | SatisfactionStack.emplace_back(Args&: Can, Args: ID); |
| 14887 | } |
| 14888 | |
| 14889 | void PopSatisfactionStackEntry() { SatisfactionStack.pop_back(); } |
| 14890 | |
| 14891 | bool SatisfactionStackContains(const NamedDecl *D, |
| 14892 | const llvm::FoldingSetNodeID &ID) const { |
| 14893 | const NamedDecl *Can = cast<NamedDecl>(Val: D->getCanonicalDecl()); |
| 14894 | return llvm::is_contained(Range: SatisfactionStack, |
| 14895 | Element: SatisfactionStackEntryTy{Can, ID}); |
| 14896 | } |
| 14897 | |
| 14898 | using SatisfactionStackEntryTy = |
| 14899 | std::pair<const NamedDecl *, llvm::FoldingSetNodeID>; |
| 14900 | |
| 14901 | // Resets the current SatisfactionStack for cases where we are instantiating |
| 14902 | // constraints as a 'side effect' of normal instantiation in a way that is not |
| 14903 | // indicative of recursive definition. |
| 14904 | class SatisfactionStackResetRAII { |
| 14905 | llvm::SmallVector<SatisfactionStackEntryTy, 10> BackupSatisfactionStack; |
| 14906 | Sema &SemaRef; |
| 14907 | |
| 14908 | public: |
| 14909 | SatisfactionStackResetRAII(Sema &S) : SemaRef(S) { |
| 14910 | SemaRef.SwapSatisfactionStack(NewSS&: BackupSatisfactionStack); |
| 14911 | } |
| 14912 | |
| 14913 | ~SatisfactionStackResetRAII() { |
| 14914 | SemaRef.SwapSatisfactionStack(NewSS&: BackupSatisfactionStack); |
| 14915 | } |
| 14916 | |
| 14917 | SatisfactionStackResetRAII(const SatisfactionStackResetRAII &) = delete; |
| 14918 | SatisfactionStackResetRAII & |
| 14919 | operator=(const SatisfactionStackResetRAII &) = delete; |
| 14920 | }; |
| 14921 | |
| 14922 | void SwapSatisfactionStack( |
| 14923 | llvm::SmallVectorImpl<SatisfactionStackEntryTy> &NewSS) { |
| 14924 | SatisfactionStack.swap(RHS&: NewSS); |
| 14925 | } |
| 14926 | |
| 14927 | using ConstrainedDeclOrNestedRequirement = |
| 14928 | llvm::PointerUnion<const NamedDecl *, |
| 14929 | const concepts::NestedRequirement *>; |
| 14930 | |
| 14931 | /// Check whether the given expression is a valid constraint expression. |
| 14932 | /// A diagnostic is emitted if it is not, false is returned, and |
| 14933 | /// PossibleNonPrimary will be set to true if the failure might be due to a |
| 14934 | /// non-primary expression being used as an atomic constraint. |
| 14935 | bool CheckConstraintExpression(const Expr *CE, Token NextToken = Token(), |
| 14936 | bool *PossibleNonPrimary = nullptr, |
| 14937 | bool IsTrailingRequiresClause = false); |
| 14938 | |
| 14939 | /// \brief Check whether the given list of constraint expressions are |
| 14940 | /// satisfied (as if in a 'conjunction') given template arguments. |
| 14941 | /// \param Template the template-like entity that triggered the constraints |
| 14942 | /// check (either a concept or a constrained entity). |
| 14943 | /// \param ConstraintExprs a list of constraint expressions, treated as if |
| 14944 | /// they were 'AND'ed together. |
| 14945 | /// \param TemplateArgLists the list of template arguments to substitute into |
| 14946 | /// the constraint expression. |
| 14947 | /// \param TemplateIDRange The source range of the template id that |
| 14948 | /// caused the constraints check. |
| 14949 | /// \param Satisfaction if true is returned, will contain details of the |
| 14950 | /// satisfaction, with enough information to diagnose an unsatisfied |
| 14951 | /// expression. |
| 14952 | /// \returns true if an error occurred and satisfaction could not be checked, |
| 14953 | /// false otherwise. |
| 14954 | bool CheckConstraintSatisfaction( |
| 14955 | ConstrainedDeclOrNestedRequirement Entity, |
| 14956 | ArrayRef<AssociatedConstraint> AssociatedConstraints, |
| 14957 | const MultiLevelTemplateArgumentList &TemplateArgLists, |
| 14958 | SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction, |
| 14959 | const ConceptReference *TopLevelConceptId = nullptr, |
| 14960 | Expr **ConvertedExpr = nullptr); |
| 14961 | |
| 14962 | /// Check whether the given function decl's trailing requires clause is |
| 14963 | /// satisfied, if any. Returns false and updates Satisfaction with the |
| 14964 | /// satisfaction verdict if successful, emits a diagnostic and returns true if |
| 14965 | /// an error occurred and satisfaction could not be determined. |
| 14966 | /// |
| 14967 | /// \returns true if an error occurred, false otherwise. |
| 14968 | bool CheckFunctionConstraints(const FunctionDecl *FD, |
| 14969 | ConstraintSatisfaction &Satisfaction, |
| 14970 | SourceLocation UsageLoc = SourceLocation(), |
| 14971 | bool ForOverloadResolution = false); |
| 14972 | |
| 14973 | // Calculates whether two constraint expressions are equal irrespective of a |
| 14974 | // difference in 'depth'. This takes a pair of optional 'NamedDecl's 'Old' and |
| 14975 | // 'New', which are the "source" of the constraint, since this is necessary |
| 14976 | // for figuring out the relative 'depth' of the constraint. The depth of the |
| 14977 | // 'primary template' and the 'instantiated from' templates aren't necessarily |
| 14978 | // the same, such as a case when one is a 'friend' defined in a class. |
| 14979 | bool AreConstraintExpressionsEqual(const NamedDecl *Old, |
| 14980 | const Expr *OldConstr, |
| 14981 | const TemplateCompareNewDeclInfo &New, |
| 14982 | const Expr *NewConstr); |
| 14983 | |
| 14984 | // Calculates whether the friend function depends on an enclosing template for |
| 14985 | // the purposes of [temp.friend] p9. |
| 14986 | bool FriendConstraintsDependOnEnclosingTemplate(const FunctionDecl *FD); |
| 14987 | |
| 14988 | /// \brief Ensure that the given template arguments satisfy the constraints |
| 14989 | /// associated with the given template, emitting a diagnostic if they do not. |
| 14990 | /// |
| 14991 | /// \param Template The template to which the template arguments are being |
| 14992 | /// provided. |
| 14993 | /// |
| 14994 | /// \param TemplateArgs The converted, canonicalized template arguments. |
| 14995 | /// |
| 14996 | /// \param TemplateIDRange The source range of the template id that |
| 14997 | /// caused the constraints check. |
| 14998 | /// |
| 14999 | /// \returns true if the constrains are not satisfied or could not be checked |
| 15000 | /// for satisfaction, false if the constraints are satisfied. |
| 15001 | bool EnsureTemplateArgumentListConstraints( |
| 15002 | TemplateDecl *Template, |
| 15003 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 15004 | SourceRange TemplateIDRange); |
| 15005 | |
| 15006 | bool CheckFunctionTemplateConstraints(SourceLocation PointOfInstantiation, |
| 15007 | FunctionDecl *Decl, |
| 15008 | ArrayRef<TemplateArgument> TemplateArgs, |
| 15009 | ConstraintSatisfaction &Satisfaction); |
| 15010 | |
| 15011 | /// \brief Emit diagnostics explaining why a constraint expression was deemed |
| 15012 | /// unsatisfied. |
| 15013 | /// \param First whether this is the first time an unsatisfied constraint is |
| 15014 | /// diagnosed for this error. |
| 15015 | void DiagnoseUnsatisfiedConstraint(const ConstraintSatisfaction &Satisfaction, |
| 15016 | SourceLocation Loc = {}, |
| 15017 | bool First = true); |
| 15018 | |
| 15019 | /// \brief Emit diagnostics explaining why a constraint expression was deemed |
| 15020 | /// unsatisfied. |
| 15021 | void |
| 15022 | DiagnoseUnsatisfiedConstraint(const ConceptSpecializationExpr *ConstraintExpr, |
| 15023 | bool First = true); |
| 15024 | |
| 15025 | const NormalizedConstraint *getNormalizedAssociatedConstraints( |
| 15026 | ConstrainedDeclOrNestedRequirement Entity, |
| 15027 | ArrayRef<AssociatedConstraint> AssociatedConstraints); |
| 15028 | |
| 15029 | /// \brief Check whether the given declaration's associated constraints are |
| 15030 | /// at least as constrained than another declaration's according to the |
| 15031 | /// partial ordering of constraints. |
| 15032 | /// |
| 15033 | /// \param Result If no error occurred, receives the result of true if D1 is |
| 15034 | /// at least constrained than D2, and false otherwise. |
| 15035 | /// |
| 15036 | /// \returns true if an error occurred, false otherwise. |
| 15037 | bool IsAtLeastAsConstrained(const NamedDecl *D1, |
| 15038 | MutableArrayRef<AssociatedConstraint> AC1, |
| 15039 | const NamedDecl *D2, |
| 15040 | MutableArrayRef<AssociatedConstraint> AC2, |
| 15041 | bool &Result); |
| 15042 | |
| 15043 | /// If D1 was not at least as constrained as D2, but would've been if a pair |
| 15044 | /// of atomic constraints involved had been declared in a concept and not |
| 15045 | /// repeated in two separate places in code. |
| 15046 | /// \returns true if such a diagnostic was emitted, false otherwise. |
| 15047 | bool MaybeEmitAmbiguousAtomicConstraintsDiagnostic( |
| 15048 | const NamedDecl *D1, ArrayRef<AssociatedConstraint> AC1, |
| 15049 | const NamedDecl *D2, ArrayRef<AssociatedConstraint> AC2); |
| 15050 | |
| 15051 | /// Cache the satisfaction of an atomic constraint. |
| 15052 | /// The key is based on the unsubstituted expression and the parameter |
| 15053 | /// mapping. This lets us not substituting the mapping more than once, |
| 15054 | /// which is (very!) expensive. |
| 15055 | /// FIXME: this should be private. |
| 15056 | llvm::DenseMap<llvm::FoldingSetNodeID, |
| 15057 | UnsubstitutedConstraintSatisfactionCacheResult> |
| 15058 | UnsubstitutedConstraintSatisfactionCache; |
| 15059 | |
| 15060 | private: |
| 15061 | /// Caches pairs of template-like decls whose associated constraints were |
| 15062 | /// checked for subsumption and whether or not the first's constraints did in |
| 15063 | /// fact subsume the second's. |
| 15064 | llvm::DenseMap<std::pair<const NamedDecl *, const NamedDecl *>, bool> |
| 15065 | SubsumptionCache; |
| 15066 | /// Caches the normalized associated constraints of declarations (concepts or |
| 15067 | /// constrained declarations). If an error occurred while normalizing the |
| 15068 | /// associated constraints of the template or concept, nullptr will be cached |
| 15069 | /// here. |
| 15070 | llvm::DenseMap<ConstrainedDeclOrNestedRequirement, NormalizedConstraint *> |
| 15071 | NormalizationCache; |
| 15072 | |
| 15073 | /// Cache whether the associated constraint of a declaration |
| 15074 | /// is satisfied. |
| 15075 | llvm::ContextualFoldingSet<ConstraintSatisfaction, const ASTContext &> |
| 15076 | SatisfactionCache; |
| 15077 | |
| 15078 | // The current stack of constraint satisfactions, so we can exit-early. |
| 15079 | llvm::SmallVector<SatisfactionStackEntryTy, 10> SatisfactionStack; |
| 15080 | |
| 15081 | /// Used by SetupConstraintCheckingTemplateArgumentsAndScope to set up the |
| 15082 | /// LocalInstantiationScope of the current non-lambda function. For lambdas, |
| 15083 | /// use LambdaScopeForCallOperatorInstantiationRAII. |
| 15084 | bool |
| 15085 | SetupConstraintScope(FunctionDecl *FD, |
| 15086 | std::optional<ArrayRef<TemplateArgument>> TemplateArgs, |
| 15087 | const MultiLevelTemplateArgumentList &MLTAL, |
| 15088 | LocalInstantiationScope &Scope); |
| 15089 | |
| 15090 | /// Used during constraint checking, sets up the constraint template argument |
| 15091 | /// lists, and calls SetupConstraintScope to set up the |
| 15092 | /// LocalInstantiationScope to have the proper set of ParVarDecls configured. |
| 15093 | std::optional<MultiLevelTemplateArgumentList> |
| 15094 | SetupConstraintCheckingTemplateArgumentsAndScope( |
| 15095 | FunctionDecl *FD, std::optional<ArrayRef<TemplateArgument>> TemplateArgs, |
| 15096 | LocalInstantiationScope &Scope); |
| 15097 | |
| 15098 | ///@} |
| 15099 | |
| 15100 | // |
| 15101 | // |
| 15102 | // ------------------------------------------------------------------------- |
| 15103 | // |
| 15104 | // |
| 15105 | |
| 15106 | /// \name Types |
| 15107 | /// Implementations are in SemaType.cpp |
| 15108 | ///@{ |
| 15109 | |
| 15110 | public: |
| 15111 | /// A mapping that describes the nullability we've seen in each header file. |
| 15112 | FileNullabilityMap NullabilityMap; |
| 15113 | |
| 15114 | static int getPrintable(int I) { return I; } |
| 15115 | static unsigned getPrintable(unsigned I) { return I; } |
| 15116 | static bool getPrintable(bool B) { return B; } |
| 15117 | static const char *getPrintable(const char *S) { return S; } |
| 15118 | static StringRef getPrintable(StringRef S) { return S; } |
| 15119 | static const std::string &getPrintable(const std::string &S) { return S; } |
| 15120 | static const IdentifierInfo *getPrintable(const IdentifierInfo *II) { |
| 15121 | return II; |
| 15122 | } |
| 15123 | static DeclarationName getPrintable(DeclarationName N) { return N; } |
| 15124 | static QualType getPrintable(QualType T) { return T; } |
| 15125 | static SourceRange getPrintable(SourceRange R) { return R; } |
| 15126 | static SourceRange getPrintable(SourceLocation L) { return L; } |
| 15127 | static SourceRange getPrintable(const Expr *E) { return E->getSourceRange(); } |
| 15128 | static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange(); } |
| 15129 | |
| 15130 | enum class CompleteTypeKind { |
| 15131 | /// Apply the normal rules for complete types. In particular, |
| 15132 | /// treat all sizeless types as incomplete. |
| 15133 | Normal, |
| 15134 | |
| 15135 | /// Relax the normal rules for complete types so that they include |
| 15136 | /// sizeless built-in types. |
| 15137 | AcceptSizeless, |
| 15138 | |
| 15139 | // FIXME: Eventually we should flip the default to Normal and opt in |
| 15140 | // to AcceptSizeless rather than opt out of it. |
| 15141 | Default = AcceptSizeless |
| 15142 | }; |
| 15143 | |
| 15144 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs, |
| 15145 | const DeclSpec *DS = nullptr); |
| 15146 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVRA, |
| 15147 | const DeclSpec *DS = nullptr); |
| 15148 | |
| 15149 | /// Build a pointer type. |
| 15150 | /// |
| 15151 | /// \param T The type to which we'll be building a pointer. |
| 15152 | /// |
| 15153 | /// \param Loc The location of the entity whose type involves this |
| 15154 | /// pointer type or, if there is no such entity, the location of the |
| 15155 | /// type that will have pointer type. |
| 15156 | /// |
| 15157 | /// \param Entity The name of the entity that involves the pointer |
| 15158 | /// type, if known. |
| 15159 | /// |
| 15160 | /// \returns A suitable pointer type, if there are no |
| 15161 | /// errors. Otherwise, returns a NULL type. |
| 15162 | QualType BuildPointerType(QualType T, SourceLocation Loc, |
| 15163 | DeclarationName Entity); |
| 15164 | |
| 15165 | /// Build a reference type. |
| 15166 | /// |
| 15167 | /// \param T The type to which we'll be building a reference. |
| 15168 | /// |
| 15169 | /// \param Loc The location of the entity whose type involves this |
| 15170 | /// reference type or, if there is no such entity, the location of the |
| 15171 | /// type that will have reference type. |
| 15172 | /// |
| 15173 | /// \param Entity The name of the entity that involves the reference |
| 15174 | /// type, if known. |
| 15175 | /// |
| 15176 | /// \returns A suitable reference type, if there are no |
| 15177 | /// errors. Otherwise, returns a NULL type. |
| 15178 | QualType BuildReferenceType(QualType T, bool LValueRef, SourceLocation Loc, |
| 15179 | DeclarationName Entity); |
| 15180 | |
| 15181 | /// Build an array type. |
| 15182 | /// |
| 15183 | /// \param T The type of each element in the array. |
| 15184 | /// |
| 15185 | /// \param ASM C99 array size modifier (e.g., '*', 'static'). |
| 15186 | /// |
| 15187 | /// \param ArraySize Expression describing the size of the array. |
| 15188 | /// |
| 15189 | /// \param Brackets The range from the opening '[' to the closing ']'. |
| 15190 | /// |
| 15191 | /// \param Entity The name of the entity that involves the array |
| 15192 | /// type, if known. |
| 15193 | /// |
| 15194 | /// \returns A suitable array type, if there are no errors. Otherwise, |
| 15195 | /// returns a NULL type. |
| 15196 | QualType BuildArrayType(QualType T, ArraySizeModifier ASM, Expr *ArraySize, |
| 15197 | unsigned Quals, SourceRange Brackets, |
| 15198 | DeclarationName Entity); |
| 15199 | QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc); |
| 15200 | |
| 15201 | /// Build an ext-vector type. |
| 15202 | /// |
| 15203 | /// Run the required checks for the extended vector type. |
| 15204 | QualType BuildExtVectorType(QualType T, Expr *ArraySize, |
| 15205 | SourceLocation AttrLoc); |
| 15206 | QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns, |
| 15207 | SourceLocation AttrLoc); |
| 15208 | |
| 15209 | QualType BuildCountAttributedArrayOrPointerType(QualType WrappedTy, |
| 15210 | Expr *CountExpr, |
| 15211 | bool CountInBytes, |
| 15212 | bool OrNull); |
| 15213 | |
| 15214 | /// BuildAddressSpaceAttr - Builds a DependentAddressSpaceType if an |
| 15215 | /// expression is uninstantiated. If instantiated it will apply the |
| 15216 | /// appropriate address space to the type. This function allows dependent |
| 15217 | /// template variables to be used in conjunction with the address_space |
| 15218 | /// attribute |
| 15219 | QualType BuildAddressSpaceAttr(QualType &T, LangAS ASIdx, Expr *AddrSpace, |
| 15220 | SourceLocation AttrLoc); |
| 15221 | |
| 15222 | /// Same as above, but constructs the AddressSpace index if not provided. |
| 15223 | QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace, |
| 15224 | SourceLocation AttrLoc); |
| 15225 | |
| 15226 | bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc); |
| 15227 | |
| 15228 | bool CheckFunctionReturnType(QualType T, SourceLocation Loc); |
| 15229 | |
| 15230 | /// Build a function type. |
| 15231 | /// |
| 15232 | /// This routine checks the function type according to C++ rules and |
| 15233 | /// under the assumption that the result type and parameter types have |
| 15234 | /// just been instantiated from a template. It therefore duplicates |
| 15235 | /// some of the behavior of GetTypeForDeclarator, but in a much |
| 15236 | /// simpler form that is only suitable for this narrow use case. |
| 15237 | /// |
| 15238 | /// \param T The return type of the function. |
| 15239 | /// |
| 15240 | /// \param ParamTypes The parameter types of the function. This array |
| 15241 | /// will be modified to account for adjustments to the types of the |
| 15242 | /// function parameters. |
| 15243 | /// |
| 15244 | /// \param Loc The location of the entity whose type involves this |
| 15245 | /// function type or, if there is no such entity, the location of the |
| 15246 | /// type that will have function type. |
| 15247 | /// |
| 15248 | /// \param Entity The name of the entity that involves the function |
| 15249 | /// type, if known. |
| 15250 | /// |
| 15251 | /// \param EPI Extra information about the function type. Usually this will |
| 15252 | /// be taken from an existing function with the same prototype. |
| 15253 | /// |
| 15254 | /// \returns A suitable function type, if there are no errors. The |
| 15255 | /// unqualified type will always be a FunctionProtoType. |
| 15256 | /// Otherwise, returns a NULL type. |
| 15257 | QualType BuildFunctionType(QualType T, MutableArrayRef<QualType> ParamTypes, |
| 15258 | SourceLocation Loc, DeclarationName Entity, |
| 15259 | const FunctionProtoType::ExtProtoInfo &EPI); |
| 15260 | |
| 15261 | /// Build a member pointer type \c T Class::*. |
| 15262 | /// |
| 15263 | /// \param T the type to which the member pointer refers. |
| 15264 | /// \param Class the class type into which the member pointer points. |
| 15265 | /// \param Loc the location where this type begins |
| 15266 | /// \param Entity the name of the entity that will have this member pointer |
| 15267 | /// type |
| 15268 | /// |
| 15269 | /// \returns a member pointer type, if successful, or a NULL type if there was |
| 15270 | /// an error. |
| 15271 | QualType BuildMemberPointerType(QualType T, const CXXScopeSpec &SS, |
| 15272 | CXXRecordDecl *Cls, SourceLocation Loc, |
| 15273 | DeclarationName Entity); |
| 15274 | |
| 15275 | /// Build a block pointer type. |
| 15276 | /// |
| 15277 | /// \param T The type to which we'll be building a block pointer. |
| 15278 | /// |
| 15279 | /// \param Loc The source location, used for diagnostics. |
| 15280 | /// |
| 15281 | /// \param Entity The name of the entity that involves the block pointer |
| 15282 | /// type, if known. |
| 15283 | /// |
| 15284 | /// \returns A suitable block pointer type, if there are no |
| 15285 | /// errors. Otherwise, returns a NULL type. |
| 15286 | QualType BuildBlockPointerType(QualType T, SourceLocation Loc, |
| 15287 | DeclarationName Entity); |
| 15288 | |
| 15289 | /// Build a paren type including \p T. |
| 15290 | QualType BuildParenType(QualType T); |
| 15291 | QualType BuildAtomicType(QualType T, SourceLocation Loc); |
| 15292 | |
| 15293 | /// Build a Read-only Pipe type. |
| 15294 | /// |
| 15295 | /// \param T The type to which we'll be building a Pipe. |
| 15296 | /// |
| 15297 | /// \param Loc We do not use it for now. |
| 15298 | /// |
| 15299 | /// \returns A suitable pipe type, if there are no errors. Otherwise, returns |
| 15300 | /// a NULL type. |
| 15301 | QualType BuildReadPipeType(QualType T, SourceLocation Loc); |
| 15302 | |
| 15303 | /// Build a Write-only Pipe type. |
| 15304 | /// |
| 15305 | /// \param T The type to which we'll be building a Pipe. |
| 15306 | /// |
| 15307 | /// \param Loc We do not use it for now. |
| 15308 | /// |
| 15309 | /// \returns A suitable pipe type, if there are no errors. Otherwise, returns |
| 15310 | /// a NULL type. |
| 15311 | QualType BuildWritePipeType(QualType T, SourceLocation Loc); |
| 15312 | |
| 15313 | /// Build a bit-precise integer type. |
| 15314 | /// |
| 15315 | /// \param IsUnsigned Boolean representing the signedness of the type. |
| 15316 | /// |
| 15317 | /// \param BitWidth Size of this int type in bits, or an expression |
| 15318 | /// representing that. |
| 15319 | /// |
| 15320 | /// \param Loc Location of the keyword. |
| 15321 | QualType BuildBitIntType(bool IsUnsigned, Expr *BitWidth, SourceLocation Loc); |
| 15322 | |
| 15323 | /// GetTypeForDeclarator - Convert the type for the specified |
| 15324 | /// declarator to Type instances. |
| 15325 | /// |
| 15326 | /// The result of this call will never be null, but the associated |
| 15327 | /// type may be a null type if there's an unrecoverable error. |
| 15328 | TypeSourceInfo *GetTypeForDeclarator(Declarator &D); |
| 15329 | TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy); |
| 15330 | |
| 15331 | /// Package the given type and TSI into a ParsedType. |
| 15332 | ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo); |
| 15333 | static QualType GetTypeFromParser(ParsedType Ty, |
| 15334 | TypeSourceInfo **TInfo = nullptr); |
| 15335 | |
| 15336 | TypeResult ActOnTypeName(Declarator &D); |
| 15337 | |
| 15338 | // Check whether the size of array element of type \p EltTy is a multiple of |
| 15339 | // its alignment and return false if it isn't. |
| 15340 | bool checkArrayElementAlignment(QualType EltTy, SourceLocation Loc); |
| 15341 | |
| 15342 | void |
| 15343 | diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals, |
| 15344 | SourceLocation FallbackLoc, |
| 15345 | SourceLocation ConstQualLoc = SourceLocation(), |
| 15346 | SourceLocation VolatileQualLoc = SourceLocation(), |
| 15347 | SourceLocation RestrictQualLoc = SourceLocation(), |
| 15348 | SourceLocation AtomicQualLoc = SourceLocation(), |
| 15349 | SourceLocation UnalignedQualLoc = SourceLocation()); |
| 15350 | |
| 15351 | /// Retrieve the keyword associated |
| 15352 | IdentifierInfo *getNullabilityKeyword(NullabilityKind nullability); |
| 15353 | |
| 15354 | /// Adjust the calling convention of a method to be the ABI default if it |
| 15355 | /// wasn't specified explicitly. This handles method types formed from |
| 15356 | /// function type typedefs and typename template arguments. |
| 15357 | void adjustMemberFunctionCC(QualType &T, bool HasThisPointer, |
| 15358 | bool IsCtorOrDtor, SourceLocation Loc); |
| 15359 | |
| 15360 | // Check if there is an explicit attribute, but only look through parens. |
| 15361 | // The intent is to look for an attribute on the current declarator, but not |
| 15362 | // one that came from a typedef. |
| 15363 | bool hasExplicitCallingConv(QualType T); |
| 15364 | |
| 15365 | /// Check whether a nullability type specifier can be added to the given |
| 15366 | /// type through some means not written in source (e.g. API notes). |
| 15367 | /// |
| 15368 | /// \param Type The type to which the nullability specifier will be |
| 15369 | /// added. On success, this type will be updated appropriately. |
| 15370 | /// |
| 15371 | /// \param Nullability The nullability specifier to add. |
| 15372 | /// |
| 15373 | /// \param DiagLoc The location to use for diagnostics. |
| 15374 | /// |
| 15375 | /// \param AllowArrayTypes Whether to accept nullability specifiers on an |
| 15376 | /// array type (e.g., because it will decay to a pointer). |
| 15377 | /// |
| 15378 | /// \param OverrideExisting Whether to override an existing, locally-specified |
| 15379 | /// nullability specifier rather than complaining about the conflict. |
| 15380 | /// |
| 15381 | /// \returns true if nullability cannot be applied, false otherwise. |
| 15382 | bool CheckImplicitNullabilityTypeSpecifier(QualType &Type, |
| 15383 | NullabilityKind Nullability, |
| 15384 | SourceLocation DiagLoc, |
| 15385 | bool AllowArrayTypes, |
| 15386 | bool OverrideExisting); |
| 15387 | |
| 15388 | /// Check whether the given variable declaration has a size that fits within |
| 15389 | /// the address space it is declared in. This issues a diagnostic if not. |
| 15390 | /// |
| 15391 | /// \param VD The variable declaration to check the size of. |
| 15392 | /// |
| 15393 | /// \param AS The address space to check the size of \p VD against. |
| 15394 | /// |
| 15395 | /// \returns true if the variable's size fits within the address space, false |
| 15396 | /// otherwise. |
| 15397 | bool CheckVarDeclSizeAddressSpace(const VarDecl *VD, LangAS AS); |
| 15398 | |
| 15399 | /// Get the type of expression E, triggering instantiation to complete the |
| 15400 | /// type if necessary -- that is, if the expression refers to a templated |
| 15401 | /// static data member of incomplete array type. |
| 15402 | /// |
| 15403 | /// May still return an incomplete type if instantiation was not possible or |
| 15404 | /// if the type is incomplete for a different reason. Use |
| 15405 | /// RequireCompleteExprType instead if a diagnostic is expected for an |
| 15406 | /// incomplete expression type. |
| 15407 | QualType getCompletedType(Expr *E); |
| 15408 | |
| 15409 | void completeExprArrayBound(Expr *E); |
| 15410 | |
| 15411 | /// Ensure that the type of the given expression is complete. |
| 15412 | /// |
| 15413 | /// This routine checks whether the expression \p E has a complete type. If |
| 15414 | /// the expression refers to an instantiable construct, that instantiation is |
| 15415 | /// performed as needed to complete its type. Furthermore |
| 15416 | /// Sema::RequireCompleteType is called for the expression's type (or in the |
| 15417 | /// case of a reference type, the referred-to type). |
| 15418 | /// |
| 15419 | /// \param E The expression whose type is required to be complete. |
| 15420 | /// \param Kind Selects which completeness rules should be applied. |
| 15421 | /// \param Diagnoser The object that will emit a diagnostic if the type is |
| 15422 | /// incomplete. |
| 15423 | /// |
| 15424 | /// \returns \c true if the type of \p E is incomplete and diagnosed, \c false |
| 15425 | /// otherwise. |
| 15426 | bool RequireCompleteExprType(Expr *E, CompleteTypeKind Kind, |
| 15427 | TypeDiagnoser &Diagnoser); |
| 15428 | bool RequireCompleteExprType(Expr *E, unsigned DiagID); |
| 15429 | |
| 15430 | template <typename... Ts> |
| 15431 | bool RequireCompleteExprType(Expr *E, unsigned DiagID, const Ts &...Args) { |
| 15432 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
| 15433 | return RequireCompleteExprType(E, CompleteTypeKind::Default, Diagnoser); |
| 15434 | } |
| 15435 | |
| 15436 | // Returns the underlying type of a decltype with the given expression. |
| 15437 | QualType getDecltypeForExpr(Expr *E); |
| 15438 | |
| 15439 | QualType BuildTypeofExprType(Expr *E, TypeOfKind Kind); |
| 15440 | /// If AsUnevaluated is false, E is treated as though it were an evaluated |
| 15441 | /// context, such as when building a type for decltype(auto). |
| 15442 | QualType BuildDecltypeType(Expr *E, bool AsUnevaluated = true); |
| 15443 | |
| 15444 | QualType ActOnPackIndexingType(QualType Pattern, Expr *IndexExpr, |
| 15445 | SourceLocation Loc, |
| 15446 | SourceLocation EllipsisLoc); |
| 15447 | QualType BuildPackIndexingType(QualType Pattern, Expr *IndexExpr, |
| 15448 | SourceLocation Loc, SourceLocation EllipsisLoc, |
| 15449 | bool FullySubstituted = false, |
| 15450 | ArrayRef<QualType> Expansions = {}); |
| 15451 | |
| 15452 | using UTTKind = UnaryTransformType::UTTKind; |
| 15453 | QualType BuildUnaryTransformType(QualType BaseType, UTTKind UKind, |
| 15454 | SourceLocation Loc); |
| 15455 | QualType BuiltinEnumUnderlyingType(QualType BaseType, SourceLocation Loc); |
| 15456 | QualType BuiltinAddPointer(QualType BaseType, SourceLocation Loc); |
| 15457 | QualType BuiltinRemovePointer(QualType BaseType, SourceLocation Loc); |
| 15458 | QualType BuiltinDecay(QualType BaseType, SourceLocation Loc); |
| 15459 | QualType BuiltinAddReference(QualType BaseType, UTTKind UKind, |
| 15460 | SourceLocation Loc); |
| 15461 | QualType BuiltinRemoveExtent(QualType BaseType, UTTKind UKind, |
| 15462 | SourceLocation Loc); |
| 15463 | QualType BuiltinRemoveReference(QualType BaseType, UTTKind UKind, |
| 15464 | SourceLocation Loc); |
| 15465 | |
| 15466 | QualType BuiltinRemoveCVRef(QualType BaseType, SourceLocation Loc) { |
| 15467 | return BuiltinRemoveReference(BaseType, UKind: UTTKind::RemoveCVRef, Loc); |
| 15468 | } |
| 15469 | |
| 15470 | QualType BuiltinChangeCVRQualifiers(QualType BaseType, UTTKind UKind, |
| 15471 | SourceLocation Loc); |
| 15472 | QualType BuiltinChangeSignedness(QualType BaseType, UTTKind UKind, |
| 15473 | SourceLocation Loc); |
| 15474 | |
| 15475 | bool BuiltinIsBaseOf(SourceLocation RhsTLoc, QualType LhsT, QualType RhsT); |
| 15476 | |
| 15477 | /// Ensure that the type T is a literal type. |
| 15478 | /// |
| 15479 | /// This routine checks whether the type @p T is a literal type. If @p T is an |
| 15480 | /// incomplete type, an attempt is made to complete it. If @p T is a literal |
| 15481 | /// type, or @p AllowIncompleteType is true and @p T is an incomplete type, |
| 15482 | /// returns false. Otherwise, this routine issues the diagnostic @p PD (giving |
| 15483 | /// it the type @p T), along with notes explaining why the type is not a |
| 15484 | /// literal type, and returns true. |
| 15485 | /// |
| 15486 | /// @param Loc The location in the source that the non-literal type |
| 15487 | /// diagnostic should refer to. |
| 15488 | /// |
| 15489 | /// @param T The type that this routine is examining for literalness. |
| 15490 | /// |
| 15491 | /// @param Diagnoser Emits a diagnostic if T is not a literal type. |
| 15492 | /// |
| 15493 | /// @returns @c true if @p T is not a literal type and a diagnostic was |
| 15494 | /// emitted, @c false otherwise. |
| 15495 | bool RequireLiteralType(SourceLocation Loc, QualType T, |
| 15496 | TypeDiagnoser &Diagnoser); |
| 15497 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID); |
| 15498 | |
| 15499 | template <typename... Ts> |
| 15500 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID, |
| 15501 | const Ts &...Args) { |
| 15502 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
| 15503 | return RequireLiteralType(Loc, T, Diagnoser); |
| 15504 | } |
| 15505 | |
| 15506 | bool isCompleteType(SourceLocation Loc, QualType T, |
| 15507 | CompleteTypeKind Kind = CompleteTypeKind::Default) { |
| 15508 | return !RequireCompleteTypeImpl(Loc, T, Kind, Diagnoser: nullptr); |
| 15509 | } |
| 15510 | |
| 15511 | /// Ensure that the type T is a complete type. |
| 15512 | /// |
| 15513 | /// This routine checks whether the type @p T is complete in any |
| 15514 | /// context where a complete type is required. If @p T is a complete |
| 15515 | /// type, returns false. If @p T is a class template specialization, |
| 15516 | /// this routine then attempts to perform class template |
| 15517 | /// instantiation. If instantiation fails, or if @p T is incomplete |
| 15518 | /// and cannot be completed, issues the diagnostic @p diag (giving it |
| 15519 | /// the type @p T) and returns true. |
| 15520 | /// |
| 15521 | /// @param Loc The location in the source that the incomplete type |
| 15522 | /// diagnostic should refer to. |
| 15523 | /// |
| 15524 | /// @param T The type that this routine is examining for completeness. |
| 15525 | /// |
| 15526 | /// @param Kind Selects which completeness rules should be applied. |
| 15527 | /// |
| 15528 | /// @returns @c true if @p T is incomplete and a diagnostic was emitted, |
| 15529 | /// @c false otherwise. |
| 15530 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
| 15531 | CompleteTypeKind Kind, TypeDiagnoser &Diagnoser); |
| 15532 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
| 15533 | CompleteTypeKind Kind, unsigned DiagID); |
| 15534 | |
| 15535 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
| 15536 | TypeDiagnoser &Diagnoser) { |
| 15537 | return RequireCompleteType(Loc, T, Kind: CompleteTypeKind::Default, Diagnoser); |
| 15538 | } |
| 15539 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID) { |
| 15540 | return RequireCompleteType(Loc, T, Kind: CompleteTypeKind::Default, DiagID); |
| 15541 | } |
| 15542 | |
| 15543 | template <typename... Ts> |
| 15544 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID, |
| 15545 | const Ts &...Args) { |
| 15546 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
| 15547 | return RequireCompleteType(Loc, T, Diagnoser); |
| 15548 | } |
| 15549 | |
| 15550 | /// Determine whether a declaration is visible to name lookup. |
| 15551 | bool isVisible(const NamedDecl *D) { |
| 15552 | return D->isUnconditionallyVisible() || |
| 15553 | isAcceptableSlow(D, Kind: AcceptableKind::Visible); |
| 15554 | } |
| 15555 | |
| 15556 | /// Determine whether a declaration is reachable. |
| 15557 | bool isReachable(const NamedDecl *D) { |
| 15558 | // All visible declarations are reachable. |
| 15559 | return D->isUnconditionallyVisible() || |
| 15560 | isAcceptableSlow(D, Kind: AcceptableKind::Reachable); |
| 15561 | } |
| 15562 | |
| 15563 | /// Determine whether a declaration is acceptable (visible/reachable). |
| 15564 | bool isAcceptable(const NamedDecl *D, AcceptableKind Kind) { |
| 15565 | return Kind == AcceptableKind::Visible ? isVisible(D) : isReachable(D); |
| 15566 | } |
| 15567 | |
| 15568 | /// Determine if \p D and \p Suggested have a structurally compatible |
| 15569 | /// layout as described in C11 6.2.7/1. |
| 15570 | bool hasStructuralCompatLayout(Decl *D, Decl *Suggested); |
| 15571 | |
| 15572 | /// Determine if \p D has a visible definition. If not, suggest a declaration |
| 15573 | /// that should be made visible to expose the definition. |
| 15574 | bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested, |
| 15575 | bool OnlyNeedComplete = false); |
| 15576 | bool hasVisibleDefinition(const NamedDecl *D) { |
| 15577 | NamedDecl *Hidden; |
| 15578 | return hasVisibleDefinition(D: const_cast<NamedDecl *>(D), Suggested: &Hidden); |
| 15579 | } |
| 15580 | /// Determine if \p D has a definition which allows we redefine it in current |
| 15581 | /// TU. \p Suggested is the definition that should be made visible to expose |
| 15582 | /// the definition. |
| 15583 | bool isRedefinitionAllowedFor(NamedDecl *D, NamedDecl **Suggested, |
| 15584 | bool &Visible); |
| 15585 | bool isRedefinitionAllowedFor(const NamedDecl *D, bool &Visible) { |
| 15586 | NamedDecl *Hidden; |
| 15587 | return isRedefinitionAllowedFor(D: const_cast<NamedDecl *>(D), Suggested: &Hidden, |
| 15588 | Visible); |
| 15589 | } |
| 15590 | |
| 15591 | /// Determine if \p D has a reachable definition. If not, suggest a |
| 15592 | /// declaration that should be made reachable to expose the definition. |
| 15593 | bool hasReachableDefinition(NamedDecl *D, NamedDecl **Suggested, |
| 15594 | bool OnlyNeedComplete = false); |
| 15595 | bool hasReachableDefinition(NamedDecl *D) { |
| 15596 | NamedDecl *Hidden; |
| 15597 | return hasReachableDefinition(D, Suggested: &Hidden); |
| 15598 | } |
| 15599 | |
| 15600 | bool hasAcceptableDefinition(NamedDecl *D, NamedDecl **Suggested, |
| 15601 | AcceptableKind Kind, |
| 15602 | bool OnlyNeedComplete = false); |
| 15603 | bool hasAcceptableDefinition(NamedDecl *D, AcceptableKind Kind) { |
| 15604 | NamedDecl *Hidden; |
| 15605 | return hasAcceptableDefinition(D, Suggested: &Hidden, Kind); |
| 15606 | } |
| 15607 | |
| 15608 | /// Try to parse the conditional expression attached to an effect attribute |
| 15609 | /// (e.g. 'nonblocking'). (c.f. Sema::ActOnNoexceptSpec). Return an empty |
| 15610 | /// optional on error. |
| 15611 | std::optional<FunctionEffectMode> |
| 15612 | ActOnEffectExpression(Expr *CondExpr, StringRef AttributeName); |
| 15613 | |
| 15614 | void ActOnCleanupAttr(Decl *D, const Attr *A); |
| 15615 | void ActOnInitPriorityAttr(Decl *D, const Attr *A); |
| 15616 | |
| 15617 | private: |
| 15618 | /// The implementation of RequireCompleteType |
| 15619 | bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T, |
| 15620 | CompleteTypeKind Kind, TypeDiagnoser *Diagnoser); |
| 15621 | |
| 15622 | /// Nullability type specifiers. |
| 15623 | IdentifierInfo *Ident__Nonnull = nullptr; |
| 15624 | IdentifierInfo *Ident__Nullable = nullptr; |
| 15625 | IdentifierInfo *Ident__Nullable_result = nullptr; |
| 15626 | IdentifierInfo *Ident__Null_unspecified = nullptr; |
| 15627 | |
| 15628 | ///@} |
| 15629 | |
| 15630 | // |
| 15631 | // |
| 15632 | // ------------------------------------------------------------------------- |
| 15633 | // |
| 15634 | // |
| 15635 | |
| 15636 | /// \name FixIt Helpers |
| 15637 | /// Implementations are in SemaFixItUtils.cpp |
| 15638 | ///@{ |
| 15639 | |
| 15640 | public: |
| 15641 | /// Get a string to suggest for zero-initialization of a type. |
| 15642 | std::string getFixItZeroInitializerForType(QualType T, |
| 15643 | SourceLocation Loc) const; |
| 15644 | std::string getFixItZeroLiteralForType(QualType T, SourceLocation Loc) const; |
| 15645 | |
| 15646 | ///@} |
| 15647 | |
| 15648 | // |
| 15649 | // |
| 15650 | // ------------------------------------------------------------------------- |
| 15651 | // |
| 15652 | // |
| 15653 | |
| 15654 | /// \name Function Effects |
| 15655 | /// Implementations are in SemaFunctionEffects.cpp |
| 15656 | ///@{ |
| 15657 | public: |
| 15658 | struct FunctionEffectDiff { |
| 15659 | enum class Kind { Added, Removed, ConditionMismatch }; |
| 15660 | |
| 15661 | FunctionEffect::Kind EffectKind; |
| 15662 | Kind DiffKind; |
| 15663 | std::optional<FunctionEffectWithCondition> |
| 15664 | Old; // Invalid when 'Kind' is 'Added'. |
| 15665 | std::optional<FunctionEffectWithCondition> |
| 15666 | New; // Invalid when 'Kind' is 'Removed'. |
| 15667 | |
| 15668 | StringRef effectName() const { |
| 15669 | if (Old) |
| 15670 | return Old.value().Effect.name(); |
| 15671 | return New.value().Effect.name(); |
| 15672 | } |
| 15673 | |
| 15674 | /// Describes the result of effects differing between a base class's virtual |
| 15675 | /// method and an overriding method in a subclass. |
| 15676 | enum class OverrideResult { |
| 15677 | NoAction, |
| 15678 | Warn, |
| 15679 | Merge // Merge missing effect from base to derived. |
| 15680 | }; |
| 15681 | |
| 15682 | /// Return true if adding or removing the effect as part of a type |
| 15683 | /// conversion should generate a diagnostic. |
| 15684 | bool shouldDiagnoseConversion(QualType SrcType, |
| 15685 | const FunctionEffectsRef &SrcFX, |
| 15686 | QualType DstType, |
| 15687 | const FunctionEffectsRef &DstFX) const; |
| 15688 | |
| 15689 | /// Return true if adding or removing the effect in a redeclaration should |
| 15690 | /// generate a diagnostic. |
| 15691 | bool shouldDiagnoseRedeclaration(const FunctionDecl &OldFunction, |
| 15692 | const FunctionEffectsRef &OldFX, |
| 15693 | const FunctionDecl &NewFunction, |
| 15694 | const FunctionEffectsRef &NewFX) const; |
| 15695 | |
| 15696 | /// Return true if adding or removing the effect in a C++ virtual method |
| 15697 | /// override should generate a diagnostic. |
| 15698 | OverrideResult shouldDiagnoseMethodOverride( |
| 15699 | const CXXMethodDecl &OldMethod, const FunctionEffectsRef &OldFX, |
| 15700 | const CXXMethodDecl &NewMethod, const FunctionEffectsRef &NewFX) const; |
| 15701 | }; |
| 15702 | |
| 15703 | struct FunctionEffectDiffVector : public SmallVector<FunctionEffectDiff> { |
| 15704 | /// Caller should short-circuit by checking for equality first. |
| 15705 | FunctionEffectDiffVector(const FunctionEffectsRef &Old, |
| 15706 | const FunctionEffectsRef &New); |
| 15707 | }; |
| 15708 | |
| 15709 | /// All functions/lambdas/blocks which have bodies and which have a non-empty |
| 15710 | /// FunctionEffectsRef to be verified. |
| 15711 | SmallVector<const Decl *> DeclsWithEffectsToVerify; |
| 15712 | |
| 15713 | /// The union of all effects present on DeclsWithEffectsToVerify. Conditions |
| 15714 | /// are all null. |
| 15715 | FunctionEffectKindSet AllEffectsToVerify; |
| 15716 | |
| 15717 | public: |
| 15718 | /// Warn and return true if adding a function effect to a set would create a |
| 15719 | /// conflict. |
| 15720 | bool diagnoseConflictingFunctionEffect(const FunctionEffectsRef &FX, |
| 15721 | const FunctionEffectWithCondition &EC, |
| 15722 | SourceLocation NewAttrLoc); |
| 15723 | |
| 15724 | // Report a failure to merge function effects between declarations due to a |
| 15725 | // conflict. |
| 15726 | void |
| 15727 | diagnoseFunctionEffectMergeConflicts(const FunctionEffectSet::Conflicts &Errs, |
| 15728 | SourceLocation NewLoc, |
| 15729 | SourceLocation OldLoc); |
| 15730 | |
| 15731 | /// Inline checks from the start of maybeAddDeclWithEffects, to |
| 15732 | /// minimize performance impact on code not using effects. |
| 15733 | template <class FuncOrBlockDecl> |
| 15734 | void maybeAddDeclWithEffects(FuncOrBlockDecl *D) { |
| 15735 | if (Context.hasAnyFunctionEffects()) |
| 15736 | if (FunctionEffectsRef FX = D->getFunctionEffects(); !FX.empty()) |
| 15737 | maybeAddDeclWithEffects(D, FX); |
| 15738 | } |
| 15739 | |
| 15740 | /// Potentially add a FunctionDecl or BlockDecl to DeclsWithEffectsToVerify. |
| 15741 | void maybeAddDeclWithEffects(const Decl *D, const FunctionEffectsRef &FX); |
| 15742 | |
| 15743 | /// Unconditionally add a Decl to DeclsWithEfffectsToVerify. |
| 15744 | void addDeclWithEffects(const Decl *D, const FunctionEffectsRef &FX); |
| 15745 | |
| 15746 | void performFunctionEffectAnalysis(TranslationUnitDecl *TU); |
| 15747 | |
| 15748 | ///@} |
| 15749 | }; |
| 15750 | |
| 15751 | DeductionFailureInfo |
| 15752 | MakeDeductionFailureInfo(ASTContext &Context, TemplateDeductionResult TDK, |
| 15753 | sema::TemplateDeductionInfo &Info); |
| 15754 | |
| 15755 | /// Contains a late templated function. |
| 15756 | /// Will be parsed at the end of the translation unit, used by Sema & Parser. |
| 15757 | struct LateParsedTemplate { |
| 15758 | CachedTokens Toks; |
| 15759 | /// The template function declaration to be late parsed. |
| 15760 | Decl *D; |
| 15761 | /// Floating-point options in the point of definition. |
| 15762 | FPOptions FPO; |
| 15763 | }; |
| 15764 | |
| 15765 | template <> |
| 15766 | void Sema::PragmaStack<Sema::AlignPackInfo>::Act(SourceLocation PragmaLocation, |
| 15767 | PragmaMsStackAction Action, |
| 15768 | llvm::StringRef StackSlotLabel, |
| 15769 | AlignPackInfo Value); |
| 15770 | |
| 15771 | } // end namespace clang |
| 15772 | |
| 15773 | #endif |
| 15774 | |