Skip to content

Commit 357362d

Browse files
committed
Add checks and diagnostics for many of the cases which C++11 considers to not
be constant expressions. llvm-svn: 146479
1 parent 8769834 commit 357362d

File tree

8 files changed

+587
-96
lines changed

8 files changed

+587
-96
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3162,6 +3162,12 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
31623162
DiagnosticsEngine::ak_nameddecl);
31633163
return DB;
31643164
}
3165+
inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
3166+
const NamedDecl* ND) {
3167+
PD.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
3168+
DiagnosticsEngine::ak_nameddecl);
3169+
return PD;
3170+
}
31653171

31663172
template<typename decl_type>
31673173
void Redeclarable<decl_type>::setPreviousDeclaration(decl_type *PrevDecl) {

clang/include/clang/Basic/DiagnosticASTKinds.td

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ def note_expr_divide_by_zero : Note<"division by zero">;
1515
def note_constexpr_invalid_cast : Note<
1616
"%select{reinterpret_cast|dynamic_cast|cast which performs the conversions of"
1717
" a reinterpret_cast|cast from %1}0 is not allowed in a constant expression">;
18+
def note_constexpr_overflow : Note<
19+
"value %0 is outside the range of representable values of type %1">;
20+
def note_constexpr_invalid_function : Note<
21+
"%select{non-constexpr|undefined}0 %select{function|constructor}1 %2 cannot "
22+
"be used in a constant expression">;
23+
def note_constexpr_nonliteral : Note<
24+
"non-literal type %0 cannot be used in a constant expression">;
25+
def note_constexpr_non_global : Note<
26+
"%select{pointer|reference}0 to %select{|subobject of }1"
27+
"%select{temporary|%4}2 %select{is not a constant expression|"
28+
"cannot be returned from a constexpr function|"
29+
"cannot be used to initialize a member in a constant expression}3">;
30+
def note_constexpr_past_end : Note<
31+
"dereferenced pointer past the end of %select{|subobject of}0 "
32+
"%select{temporary|%2}1 is not a constant expression">;
33+
def note_constexpr_temporary_here : Note<"temporary created here">;
34+
def note_constexpr_depth_limit_exceeded : Note<
35+
"constexpr evaluation exceeded maximum depth of %0 calls">;
1836

1937
// inline asm related.
2038
let CategoryName = "Inline Assembly Issue" in {

clang/include/clang/Basic/DiagnosticCommonKinds.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ let Component = "Common" in {
1818
def fatal_too_many_errors
1919
: Error<"too many errors emitted, stopping now">, DefaultFatal;
2020

21+
def note_declared_at : Note<"declared here">;
2122
def note_previous_definition : Note<"previous definition is here">;
2223
def note_previous_declaration : Note<"previous declaration is here">;
2324
def note_previous_implicit_declaration : Note<

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ def warn_strict_multiple_method_decl : Warning<
485485
"multiple methods named %0 found">, InGroup<StrictSelector>, DefaultIgnore;
486486
def warn_accessor_property_type_mismatch : Warning<
487487
"type of property %0 does not match type of accessor %1">;
488-
def note_declared_at : Note<"declared here">;
489488
def note_method_declared_at : Note<"method declared here">;
490489
def err_setter_type_void : Error<"type of setter must be void">;
491490
def err_duplicate_method_decl : Error<"duplicate declaration of method %0">;

0 commit comments

Comments
 (0)