Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
clang/lib/Sema/SemaChecking.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 14,363 Lines • ▼ Show 20 Lines | if ((!isa<EnumType>(Target) || !isa<EnumType>(Source)) && | ||||
return DiagnoseImpCast(S, E, T, CC, DiagID); | return DiagnoseImpCast(S, E, T, CC, DiagID); | ||||
} | } | ||||
// Diagnose conversions between different enumeration types. | // Diagnose conversions between different enumeration types. | ||||
// In C, we pretend that the type of an EnumConstantDecl is its enumeration | // In C, we pretend that the type of an EnumConstantDecl is its enumeration | ||||
// type, to give us better diagnostics. | // type, to give us better diagnostics. | ||||
QualType SourceType = E->getType(); | QualType SourceType = E->getType(); | ||||
if (!S.getLangOpts().CPlusPlus) { | if (!S.getLangOpts().CPlusPlus) { | ||||
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) | ||||
if (EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(DRE->getDecl())) { | if (EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(DRE->getDecl())) { | ||||
EnumDecl *Enum = cast<EnumDecl>(ECD->getDeclContext()); | EnumDecl *Enum = cast<EnumDecl>(ECD->getDeclContext()); | ||||
SourceType = S.Context.getTypeDeclType(Enum); | SourceType = S.Context.getTypeDeclType(Enum); | ||||
aaron.ballman: You might as well use `RequireCompleteExprType(E, diag::err_incomplete_type)` as it's slightly… | |||||
Not Done ReplyInline ActionsOur coding style would have you drop the curly braces here. aaron.ballman: Our coding style would have you drop the curly braces here. | |||||
Source = S.Context.getCanonicalType(SourceType).getTypePtr(); | Source = S.Context.getCanonicalType(SourceType).getTypePtr(); | ||||
} | } | ||||
} | } | ||||
if (const EnumType *SourceEnum = Source->getAs<EnumType>()) | if (const EnumType *SourceEnum = Source->getAs<EnumType>()) | ||||
if (const EnumType *TargetEnum = Target->getAs<EnumType>()) | if (const EnumType *TargetEnum = Target->getAs<EnumType>()) | ||||
if (SourceEnum->getDecl()->hasNameForLinkage() && | if (SourceEnum->getDecl()->hasNameForLinkage() && | ||||
TargetEnum->getDecl()->hasNameForLinkage() && | TargetEnum->getDecl()->hasNameForLinkage() && | ||||
SourceEnum != TargetEnum) { | SourceEnum != TargetEnum) { | ||||
if (S.SourceMgr.isInSystemMacro(CC)) | if (S.SourceMgr.isInSystemMacro(CC)) | ||||
return; | return; | ||||
return DiagnoseImpCast(S, E, SourceType, T, CC, | return DiagnoseImpCast(S, E, SourceType, T, CC, | ||||
diag::warn_impcast_different_enum_types); | diag::warn_impcast_different_enum_types); | ||||
} | } | ||||
} | } | ||||
static void CheckConditionalOperator(Sema &S, AbstractConditionalOperator *E, | static void CheckConditionalOperator(Sema &S, AbstractConditionalOperator *E, | ||||
SourceLocation CC, QualType T); | SourceLocation CC, QualType T); | ||||
static void CheckConditionalOperand(Sema &S, Expr *E, QualType T, | static void CheckConditionalOperand(Sema &S, Expr *E, QualType T, | ||||
SourceLocation CC, bool &ICContext) { | SourceLocation CC, bool &ICContext) { | ||||
E = E->IgnoreParenImpCasts(); | E = E->IgnoreParenImpCasts(); | ||||
// Diagnose incomplete type for second or third operand in C. | |||||
if (!S.getLangOpts().CPlusPlus && E->getType()->isRecordType()) | |||||
S.RequireCompleteExprType(E, diag::err_incomplete_type); | |||||
if (auto *CO = dyn_cast<AbstractConditionalOperator>(E)) | if (auto *CO = dyn_cast<AbstractConditionalOperator>(E)) | ||||
return CheckConditionalOperator(S, CO, CC, T); | return CheckConditionalOperator(S, CO, CC, T); | ||||
AnalyzeImplicitConversions(S, E, CC); | AnalyzeImplicitConversions(S, E, CC); | ||||
if (E->getType() != T) | if (E->getType() != T) | ||||
return CheckImplicitConversion(S, E, T, CC, &ICContext); | return CheckImplicitConversion(S, E, T, CC, &ICContext); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 3,858 Lines • Show Last 20 Lines |
You might as well use RequireCompleteExprType(E, diag::err_incomplete_type) as it's slightly simpler but does the same thing.