Diagnose labels in expansion statements.
This commit is contained in:
@@ -3250,8 +3250,8 @@ def err_injected_decl_outside_cone : Error <
|
|||||||
|
|
||||||
def err_compute_expansion_size_index : Error<
|
def err_compute_expansion_size_index : Error<
|
||||||
"could not compute %select{size|index}0 of expansion">;
|
"could not compute %select{size|index}0 of expansion">;
|
||||||
def err_cannot_expand_over_type : Error<
|
def err_expanded_identifier_label : Error<
|
||||||
"cannot expand over an expression of type %0">;
|
"identifier labels are not allowed in expansion statements">;
|
||||||
|
|
||||||
// C++11 char16_t/char32_t
|
// C++11 char16_t/char32_t
|
||||||
def warn_cxx98_compat_unicode_type : Warning<
|
def warn_cxx98_compat_unicode_type : Warning<
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "clang/AST/Decl.h"
|
#include "clang/AST/Decl.h"
|
||||||
|
#include "clang/AST/DynamicRecursiveASTVisitor.h"
|
||||||
#include "clang/Basic/DiagnosticSema.h"
|
#include "clang/Basic/DiagnosticSema.h"
|
||||||
#include "clang/Lex/Preprocessor.h"
|
#include "clang/Lex/Preprocessor.h"
|
||||||
#include "clang/Sema/EnterExpressionEvaluationContext.h"
|
#include "clang/Sema/EnterExpressionEvaluationContext.h"
|
||||||
@@ -518,6 +519,18 @@ StmtResult Sema::FinishCXXExpansionStmt(Stmt *Heading, Stmt *Body) {
|
|||||||
if (!Heading || !Body)
|
if (!Heading || !Body)
|
||||||
return StmtError();
|
return StmtError();
|
||||||
|
|
||||||
|
// Diagnose identifier labels.
|
||||||
|
struct DiagnoseLabels : DynamicRecursiveASTVisitor {
|
||||||
|
Sema &SemaRef;
|
||||||
|
DiagnoseLabels(Sema &S) : SemaRef(S) {}
|
||||||
|
bool VisitLabelStmt(LabelStmt *S) override {
|
||||||
|
SemaRef.Diag(S->getIdentLoc(), diag::err_expanded_identifier_label);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} Visitor(*this);
|
||||||
|
if (!Visitor.TraverseStmt(Body))
|
||||||
|
return StmtError();
|
||||||
|
|
||||||
CXXExpansionStmt *Expansion = cast<CXXExpansionStmt>(Heading);
|
CXXExpansionStmt *Expansion = cast<CXXExpansionStmt>(Heading);
|
||||||
Expansion->setBody(Body);
|
Expansion->setBody(Body);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user