Skip to content

Commit

Permalink
-Wc++98-compat and -Wc++98-compat-pedantic warnings for Sema, part 1.
Browse files Browse the repository at this point in the history
llvm-svn: 142419
  • Loading branch information
zygoloid committed Oct 18, 2011
1 parent b274318 commit 0bf8a49
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 88 deletions.
59 changes: 52 additions & 7 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ def err_using_decl_can_not_refer_to_namespace : Error<
"using declaration can not refer to namespace">;
def err_using_decl_constructor : Error<
"using declaration can not refer to a constructor">;
def warn_cxx98_compat_using_decl_constructor : Warning<
"inherited constructors are incompatible with C++98">,
InGroup<CXX98Compat>, DefaultIgnore;
def err_using_decl_destructor : Error<
"using declaration can not refer to a destructor">;
def err_using_decl_template_id : Error<
Expand Down Expand Up @@ -623,6 +626,9 @@ def ext_nonclass_type_friend : ExtWarn<
"non-class friend type %0 is a C++11 extension">, InGroup<CXX11>;
def err_friend_is_member : Error<
"friends cannot be members of the declaring class">;
def warn_cxx98_compat_friend_is_member : Warning<
"friend declaration naming a member of the declaring class is incompatible "
"with C++98">, InGroup<CXX98Compat>, DefaultIgnore;
def ext_unelaborated_friend_type : ExtWarn<
"specify '%select{struct|union|class|enum}0' to befriend %1; accepted "
"as a C++11 extension">, InGroup<CXX11>;
Expand Down Expand Up @@ -1160,8 +1166,11 @@ def err_incomplete_type_no_underlying_type : Error<
"an incomplete enumeration type has no underlying type yet">;

// C++11 delegating constructors
def err_delegation_0x_only : Error<
def err_delegating_ctor : Error<
"delegating constructors are permitted only in C++11">;
def warn_cxx98_compat_delegating_ctor : Warning<
"delegating constructors are incompatible with C++98">,
InGroup<CXX98Compat>, DefaultIgnore;
def err_delegating_initializer_alone : Error<
"an initializer for a delegating constructor must appear alone">;
def warn_delegating_ctor_cycle : Warning<
Expand Down Expand Up @@ -2071,6 +2080,9 @@ def err_template_param_default_arg_missing : Error<
def ext_template_parameter_default_in_function_template : ExtWarn<
"default template arguments for a function template are a C++11 extension">,
InGroup<CXX11>;
def warn_cxx98_compat_template_parameter_default_in_function_template : Warning<
"default template arguments for a function template are incompatible with C++98">,
InGroup<CXX98Compat>, DefaultIgnore;
def err_template_parameter_default_template_member : Error<
"cannot add a default template argument to the definition of a member of a "
"class template">;
Expand Down Expand Up @@ -2111,6 +2123,12 @@ def ext_template_arg_local_type : ExtWarn<
"template argument uses local type %0">, InGroup<LocalTypeTemplateArgs>;
def ext_template_arg_unnamed_type : ExtWarn<
"template argument uses unnamed type">, InGroup<UnnamedTypeTemplateArgs>;
def warn_cxx98_compat_template_arg_local_type : Warning<
"local type %0 as template argument is incompatible with C++98">,
InGroup<CXX98Compat>, DefaultIgnore;
def warn_cxx98_compat_template_arg_unnamed_type : Warning<
"unnamed type as template argument is incompatible with C++98">,
InGroup<CXX98Compat>, DefaultIgnore;
def note_template_unnamed_type_here : Note<
"unnamed type used in template argument was declared here">;
def err_template_arg_overload_type : Error<
Expand Down Expand Up @@ -2178,6 +2196,9 @@ def err_template_arg_not_pointer_to_member_form : Error<
"non-type template argument is not a pointer to member constant">;
def ext_template_arg_extra_parens : ExtWarn<
"address non-type template argument cannot be surrounded by parentheses">;
def warn_cxx98_compat_template_arg_extra_parens : Warning<
"redundant parentheses surrounding address non-type template argument are "
"incompatible with C++98">, InGroup<CXX98Compat>, DefaultIgnore;
def err_pointer_to_member_type : Error<
"invalid use of pointer to member type after %select{.*|->*}0">;
def err_pointer_to_member_call_drops_quals : Error<
Expand All @@ -2203,11 +2224,6 @@ def err_template_spec_decl_out_of_scope_global : Error<
"%select{class template|class template partial|function template|member "
"function|static data member|member class}0 specialization of %1 must "
"originally be declared in the global scope">;
def ext_template_spec_decl_out_of_scope_global : ExtWarn<
"%select{class template|class template partial|function template|member "
"function|static data member|member class}0 specialization of %1 must "
"originally be declared in the global scope; accepted as a C++11 extension">,
InGroup<CXX11>;
def err_template_spec_decl_out_of_scope : Error<
"%select{class template|class template partial|function template|member "
"function|static data member|member class}0 specialization of %1 must "
Expand All @@ -2217,6 +2233,11 @@ def ext_template_spec_decl_out_of_scope : ExtWarn<
"function|static data member|member class}0 specialization of %1 must "
"originally be declared in namespace %2; accepted as a C++11 extension">,
InGroup<CXX11>;
def warn_cxx98_compat_template_spec_decl_out_of_scope : Warning<
"%select{class template|class template partial|function template|member "
"function|static data member|member class}0 specialization of %1 outside "
"namespace %2 is incompatible with C++98">,
InGroup<CXX98Compat>, DefaultIgnore;
def err_template_spec_redecl_out_of_scope : Error<
"%select{class template|class template partial|function template|member "
"function|static data member|member class}0 specialization of %1 not in a "
Expand Down Expand Up @@ -2384,6 +2405,10 @@ def ext_explicit_instantiation_after_specialization : Extension<
"explicit instantiation of %0 that occurs after an explicit "
"specialization will be ignored (C++11 extension)">,
InGroup<CXX11>;
def warn_cxx98_compat_explicit_instantiation_after_specialization : Warning<
"explicit instantiation of %0 that occurs after an explicit "
"specialization is incompatible with C++98">,
InGroup<CXX98CompatPedantic>, DefaultIgnore;
def note_previous_template_specialization : Note<
"previous template specialization is here">;
def err_explicit_instantiation_enum : Error<
Expand Down Expand Up @@ -2464,6 +2489,9 @@ def warn_typename_missing : ExtWarn<
InGroup<DiagGroup<"typename-missing">>;
def ext_typename_outside_of_template : ExtWarn<
"'typename' occurs outside of a template">, InGroup<CXX11>;
def warn_cxx98_compat_typename_outside_of_template : Warning<
"use of 'typename' outside of a template is incompatible with C++98">,
InGroup<CXX98Compat>, DefaultIgnore;
def err_typename_refers_to_using_value_decl : Error<
"typename specifier refers to a dependent using declaration for a value "
"%0 in %1">;
Expand All @@ -2482,6 +2510,9 @@ def err_template_kw_missing : Error<
"missing 'template' keyword prior to dependent template name '%0%1'">;
def ext_template_outside_of_template : ExtWarn<
"'template' keyword outside of a template">, InGroup<CXX11>;
def warn_cxx98_compat_template_outside_of_template : Warning<
"use of 'template' keyword outside of a template is incompatible with C++98">,
InGroup<CXX98Compat>, DefaultIgnore;

def err_non_type_template_in_nested_name_specifier : Error<
"qualified name refers into a specialization of function template '%0'">;
Expand Down Expand Up @@ -3623,6 +3654,9 @@ def err_bad_const_cast_dest : Error<
"which is not a reference, pointer-to-object, or pointer-to-data-member">;
def ext_cast_fn_obj : Extension<
"cast between pointer-to-function and pointer-to-object is an extension">;
def warn_cxx98_compat_cast_fn_obj : Warning<
"cast between pointer-to-function and pointer-to-object is incompatible with C++98">,
InGroup<CXX98CompatPedantic>, DefaultIgnore;
def err_bad_reinterpret_cast_small_int : Error<
"cast from pointer to smaller type %2 loses information">;
def err_bad_cxx_cast_vector_to_scalar_different_size : Error<
Expand Down Expand Up @@ -3708,6 +3742,10 @@ def ext_array_size_conversion : Extension<
"implicit conversion from array size expression of type %0 to "
"%select{integral|enumeration}1 type %2 is a C++11 extension">,
InGroup<CXX11>;
def warn_cxx98_compat_array_size_conversion : Warning<
"implicit conversion from array size expression of type %0 to "
"%select{integral|enumeration}1 type %2 is incompatible with C++98">,
InGroup<CXX98CompatPedantic>, DefaultIgnore;
def err_address_space_qualified_new : Error<
"'new' cannot allocate objects of type %0 in address space '%1'">;
def err_address_space_qualified_delete : Error<
Expand Down Expand Up @@ -4083,6 +4121,10 @@ def warn_cannot_pass_non_pod_arg_to_vararg : Warning<
"cannot pass object of %select{non-POD|non-trivial}0 type %1 through variadic"
" %select{function|block|method|constructor}2; call will abort at runtime">,
InGroup<DiagGroup<"non-pod-varargs">>, DefaultError;
def warn_cxx98_compat_pass_non_pod_arg_to_vararg : Warning<
"passing object of trivial but non-POD type %0 through variadic"
" %select{function|block|method|constructor}1 is incompatible with C++98">,
InGroup<CXX98Compat>, DefaultIgnore;

def err_typecheck_call_invalid_ordered_compare : Error<
"ordered compare requires two args of floating point type (%0 and %1)">;
Expand Down Expand Up @@ -4413,8 +4455,11 @@ def warn_not_compound_assign : Warning<
"use of unary operator that may be intended as compound assignment (%0=)">;

// C++11 explicit conversion operators
def warn_explicit_conversion_functions : Warning<
def ext_explicit_conversion_functions : ExtWarn<
"explicit conversion functions are a C++11 extension">, InGroup<CXX11>;
def warn_cxx98_compat_explicit_conversion_functions : Warning<
"explicit conversion functions are incompatible with C++98">,
InGroup<CXX98Compat>, DefaultIgnore;

// C++11 defaulted functions
def err_defaulted_default_ctor_params : Error<
Expand Down
12 changes: 8 additions & 4 deletions clang/lib/Sema/SemaCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1712,15 +1712,19 @@ static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr,
// casting the return value of dlsym() and GetProcAddress().
// FIXME: Conditionally-supported behavior should be configurable in the
// TargetInfo or similar.
if (!Self.getLangOptions().CPlusPlus0x)
Self.Diag(OpRange.getBegin(), diag::ext_cast_fn_obj) << OpRange;
Self.Diag(OpRange.getBegin(),
Self.getLangOptions().CPlusPlus0x ?
diag::warn_cxx98_compat_cast_fn_obj : diag::ext_cast_fn_obj)
<< OpRange;
return TC_Success;
}

if (DestType->isFunctionPointerType()) {
// See above.
if (!Self.getLangOptions().CPlusPlus0x)
Self.Diag(OpRange.getBegin(), diag::ext_cast_fn_obj) << OpRange;
Self.Diag(OpRange.getBegin(),
Self.getLangOptions().CPlusPlus0x ?
diag::warn_cxx98_compat_cast_fn_obj : diag::ext_cast_fn_obj)
<< OpRange;
return TC_Success;
}

Expand Down
36 changes: 24 additions & 12 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2127,8 +2127,9 @@ Sema::BuildDelegatingInitializer(TypeSourceInfo *TInfo,
CXXRecordDecl *ClassDecl) {
SourceLocation Loc = TInfo->getTypeLoc().getLocalSourceRange().getBegin();
if (!LangOpts.CPlusPlus0x)
return Diag(Loc, diag::err_delegation_0x_only)
return Diag(Loc, diag::err_delegating_ctor)
<< TInfo->getTypeLoc().getLocalSourceRange();
Diag(Loc, diag::warn_cxx98_compat_delegating_ctor);

// Initialize the object.
InitializedEntity DelegationEntity = InitializedEntity::InitializeDelegation(
Expand Down Expand Up @@ -5342,9 +5343,11 @@ void Sema::CheckConversionDeclarator(Declarator &D, QualType &R,
R = Context.getFunctionType(ConvType, 0, 0, Proto->getExtProtoInfo());

// C++0x explicit conversion operators.
if (D.getDeclSpec().isExplicitSpecified() && !getLangOptions().CPlusPlus0x)
if (D.getDeclSpec().isExplicitSpecified())
Diag(D.getDeclSpec().getExplicitSpecLoc(),
diag::warn_explicit_conversion_functions)
getLangOptions().CPlusPlus0x ?
diag::warn_cxx98_compat_explicit_conversion_functions :
diag::ext_explicit_conversion_functions)
<< SourceRange(D.getDeclSpec().getExplicitSpecLoc());
}

Expand Down Expand Up @@ -5791,10 +5794,14 @@ Decl *Sema::ActOnUsingDeclaration(Scope *S,
case UnqualifiedId::IK_ConstructorName:
case UnqualifiedId::IK_ConstructorTemplateId:
// C++0x inherited constructors.
Diag(Name.getSourceRange().getBegin(),
getLangOptions().CPlusPlus0x ?
diag::warn_cxx98_compat_using_decl_constructor :
diag::err_using_decl_constructor)
<< SS.getRange();

if (getLangOptions().CPlusPlus0x) break;

Diag(Name.getSourceRange().getBegin(), diag::err_using_decl_constructor)
<< SS.getRange();
return 0;

case UnqualifiedId::IK_DestructorName:
Expand Down Expand Up @@ -7432,7 +7439,7 @@ Sema::ComputeDefaultedCopyAssignmentExceptionSpecAndConst(
&HasConstCopyAssignment);
}

// In C++0x, the above citation has "or virtual added"
// In C++11, the above citation has "or virtual" added
if (LangOpts.CPlusPlus0x) {
for (CXXRecordDecl::base_class_iterator Base = ClassDecl->vbases_begin(),
BaseEnd = ClassDecl->vbases_end();
Expand Down Expand Up @@ -9996,12 +10003,14 @@ Decl *Sema::ActOnFriendFunctionDecl(Scope *S, Declarator &D,

// C++ [class.friend]p1: A friend of a class is a function or
// class that is not a member of the class . . .
// C++0x changes this for both friend types and functions.
// C++11 changes this for both friend types and functions.
// Most C++ 98 compilers do seem to give an error here, so
// we do, too.
if (!Previous.empty() && DC->Equals(CurContext)
&& !getLangOptions().CPlusPlus0x)
Diag(DS.getFriendSpecLoc(), diag::err_friend_is_member);
if (!Previous.empty() && DC->Equals(CurContext))
Diag(DS.getFriendSpecLoc(),
getLangOptions().CPlusPlus0x ?
diag::warn_cxx98_compat_friend_is_member :
diag::err_friend_is_member);

DCScope = getScopeForDeclContext(S, DC);

Expand Down Expand Up @@ -10045,8 +10054,11 @@ Decl *Sema::ActOnFriendFunctionDecl(Scope *S, Declarator &D,

// C++ [class.friend]p1: A friend of a class is a function or
// class that is not a member of the class . . .
if (DC->Equals(CurContext) && !getLangOptions().CPlusPlus0x)
Diag(DS.getFriendSpecLoc(), diag::err_friend_is_member);
if (DC->Equals(CurContext))
Diag(DS.getFriendSpecLoc(),
getLangOptions().CPlusPlus0x ?
diag::warn_cxx98_compat_friend_is_member :
diag::err_friend_is_member);

if (D.isFunctionDefinition()) {
// C++ [class.friend]p6:
Expand Down
13 changes: 9 additions & 4 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,12 @@ ExprResult Sema::DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT,
if (CXXRecordDecl *Record = E->getType()->getAsCXXRecordDecl()) {
if (Record->hasTrivialCopyConstructor() &&
Record->hasTrivialMoveConstructor() &&
Record->hasTrivialDestructor())
Record->hasTrivialDestructor()) {
DiagRuntimeBehavior(E->getLocStart(), 0,
PDiag(diag::warn_cxx98_compat_pass_non_pod_arg_to_vararg)
<< E->getType() << CT);
TrivialEnough = true;
}
}
}

Expand Down Expand Up @@ -2643,9 +2647,10 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
QualType Ty;

// long long is a C99 feature.
if (!getLangOptions().C99 && !getLangOptions().CPlusPlus0x &&
Literal.isLongLong)
Diag(Tok.getLocation(), diag::ext_longlong);
if (!getLangOptions().C99 && Literal.isLongLong)
Diag(Tok.getLocation(),
getLangOptions().CPlusPlus0x ?
diag::warn_cxx98_compat_longlong : diag::ext_longlong);

// Get the value in the widest-possible width.
llvm::APInt ResultVal(Context.getTargetInfo().getIntMaxTWidth(), 0);
Expand Down
23 changes: 12 additions & 11 deletions clang/lib/Sema/SemaExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,17 +963,18 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,

QualType SizeType = ArraySize->getType();

ExprResult ConvertedSize
= ConvertToIntegralOrEnumerationType(StartLoc, ArraySize,
PDiag(diag::err_array_size_not_integral),
PDiag(diag::err_array_size_incomplete_type)
<< ArraySize->getSourceRange(),
PDiag(diag::err_array_size_explicit_conversion),
PDiag(diag::note_array_size_conversion),
PDiag(diag::err_array_size_ambiguous_conversion),
PDiag(diag::note_array_size_conversion),
PDiag(getLangOptions().CPlusPlus0x? 0
: diag::ext_array_size_conversion));
ExprResult ConvertedSize = ConvertToIntegralOrEnumerationType(
StartLoc, ArraySize,
PDiag(diag::err_array_size_not_integral),
PDiag(diag::err_array_size_incomplete_type)
<< ArraySize->getSourceRange(),
PDiag(diag::err_array_size_explicit_conversion),
PDiag(diag::note_array_size_conversion),
PDiag(diag::err_array_size_ambiguous_conversion),
PDiag(diag::note_array_size_conversion),
PDiag(getLangOptions().CPlusPlus0x ?
diag::warn_cxx98_compat_array_size_conversion :
diag::ext_array_size_conversion));
if (ConvertedSize.isInvalid())
return ExprError();

Expand Down

0 comments on commit 0bf8a49

Please sign in to comment.