/* If this declarator is parenthesized, this the open-paren. It is
UNKNOWN_LOCATION when not parenthesized. */
location_t parenthesized;
-
- location_t id_loc; /* Currently only set for cdk_id, cdk_decomp and
- cdk_function. */
+ /* Currently only set for cdk_id, cdk_decomp and cdk_function. */
+ location_t id_loc;
+ /* If this declarator is part of an init-declarator, the location of the
+ initializer. */
+ location_t init_loc;
/* GNU Attributes that apply to this declarator. If the declarator
is a pointer or a reference, these attribute apply to the type
pointed to. */
extern const char *language_to_string (enum languages);
extern const char *class_key_or_enum_as_string (tree);
extern void maybe_warn_variadic_templates (void);
-extern void maybe_warn_cpp0x (cpp0x_warn_str str);
+extern void maybe_warn_cpp0x (cpp0x_warn_str str,
+ location_t = input_location);
extern bool pedwarn_cxx98 (location_t, int, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4);
extern location_t location_of (tree);
extern void qualified_name_lookup_error (tree, tree, tree,
extern void require_complete_eh_spec_types (tree, tree);
extern void cxx_incomplete_type_diagnostic (location_t, const_tree,
const_tree, diagnostic_t);
+inline location_t
+loc_or_input_loc (location_t loc)
+{
+ return loc == UNKNOWN_LOCATION ? input_location : loc;
+}
inline location_t
cp_expr_loc_or_loc (const_tree t, location_t or_loc)
if (initialized == SD_DEFAULTED || initialized == SD_DELETED)
funcdef_flag = true;
- location_t typespec_loc = smallest_type_location (type_quals,
- declspecs->locations);
- if (typespec_loc == UNKNOWN_LOCATION)
- typespec_loc = input_location;
-
- location_t id_loc = declarator ? declarator->id_loc : input_location;
- if (id_loc == UNKNOWN_LOCATION)
- id_loc = input_location;
+ location_t typespec_loc = loc_or_input_loc (smallest_type_location
+ (type_quals,
+ declspecs->locations));
+ location_t id_loc;
+ location_t init_loc;
+ if (declarator)
+ {
+ id_loc = loc_or_input_loc (declarator->id_loc);
+ init_loc = loc_or_input_loc (declarator->init_loc);
+ }
+ else
+ init_loc = id_loc = input_location;
/* Look inside a declarator for the name being declared
and get it as a string, for an error message. */
{
/* An attempt is being made to initialize a non-static
member. This is new in C++11. */
- maybe_warn_cpp0x (CPP0X_NSDMI);
+ maybe_warn_cpp0x (CPP0X_NSDMI, init_loc);
/* If this has been parsed with static storage class, but
errors forced staticp to be cleared, ensure NSDMI is
\f
/* Warn about the use of C++0x features when appropriate. */
void
-maybe_warn_cpp0x (cpp0x_warn_str str)
+maybe_warn_cpp0x (cpp0x_warn_str str, location_t loc/*=input_location*/)
{
if (cxx_dialect == cxx98)
switch (str)
{
case CPP0X_INITIALIZER_LISTS:
- pedwarn (input_location, OPT_Wc__11_extensions,
+ pedwarn (loc, OPT_Wc__11_extensions,
"extended initializer lists "
"only available with %<-std=c++11%> or %<-std=gnu++11%>");
break;
case CPP0X_EXPLICIT_CONVERSION:
- pedwarn (input_location, OPT_Wc__11_extensions,
+ pedwarn (loc, OPT_Wc__11_extensions,
"explicit conversion operators "
"only available with %<-std=c++11%> or %<-std=gnu++11%>");
break;
case CPP0X_VARIADIC_TEMPLATES:
- pedwarn (input_location, OPT_Wc__11_extensions,
+ pedwarn (loc, OPT_Wc__11_extensions,
"variadic templates "
"only available with %<-std=c++11%> or %<-std=gnu++11%>");
break;
case CPP0X_LAMBDA_EXPR:
- pedwarn (input_location, OPT_Wc__11_extensions,
+ pedwarn (loc, OPT_Wc__11_extensions,
"lambda expressions "
"only available with %<-std=c++11%> or %<-std=gnu++11%>");
break;
case CPP0X_AUTO:
- pedwarn (input_location, OPT_Wc__11_extensions,
+ pedwarn (loc, OPT_Wc__11_extensions,
"C++11 auto only available with %<-std=c++11%> or "
"%<-std=gnu++11%>");
break;
case CPP0X_SCOPED_ENUMS:
- pedwarn (input_location, OPT_Wc__11_extensions,
+ pedwarn (loc, OPT_Wc__11_extensions,
"scoped enums only available with %<-std=c++11%> or "
"%<-std=gnu++11%>");
break;
case CPP0X_DEFAULTED_DELETED:
- pedwarn (input_location, OPT_Wc__11_extensions,
+ pedwarn (loc, OPT_Wc__11_extensions,
"defaulted and deleted functions "
"only available with %<-std=c++11%> or %<-std=gnu++11%>");
break;
case CPP0X_INLINE_NAMESPACES:
if (pedantic)
- pedwarn (input_location, OPT_Wc__11_extensions,
+ pedwarn (loc, OPT_Wc__11_extensions,
"inline namespaces "
"only available with %<-std=c++11%> or %<-std=gnu++11%>");
break;
case CPP0X_OVERRIDE_CONTROLS:
- pedwarn (input_location, OPT_Wc__11_extensions,
+ pedwarn (loc, OPT_Wc__11_extensions,
"override controls (override/final) "
"only available with %<-std=c++11%> or %<-std=gnu++11%>");
break;
case CPP0X_NSDMI:
- pedwarn (input_location, OPT_Wc__11_extensions,
+ pedwarn (loc, OPT_Wc__11_extensions,
"non-static data member initializers "
"only available with %<-std=c++11%> or %<-std=gnu++11%>");
break;
case CPP0X_USER_DEFINED_LITERALS:
- pedwarn (input_location, OPT_Wc__11_extensions,
+ pedwarn (loc, OPT_Wc__11_extensions,
"user-defined literals "
"only available with %<-std=c++11%> or %<-std=gnu++11%>");
break;
case CPP0X_DELEGATING_CTORS:
- pedwarn (input_location, OPT_Wc__11_extensions,
+ pedwarn (loc, OPT_Wc__11_extensions,
"delegating constructors "
"only available with %<-std=c++11%> or %<-std=gnu++11%>");
break;
case CPP0X_INHERITING_CTORS:
- pedwarn (input_location, OPT_Wc__11_extensions,
+ pedwarn (loc, OPT_Wc__11_extensions,
"inheriting constructors "
"only available with %<-std=c++11%> or %<-std=gnu++11%>");
break;
case CPP0X_ATTRIBUTES:
- pedwarn (input_location, OPT_Wc__11_extensions,
+ pedwarn (loc, OPT_Wc__11_extensions,
"C++11 attributes "
"only available with %<-std=c++11%> or %<-std=gnu++11%>");
break;
case CPP0X_REF_QUALIFIER:
- pedwarn (input_location, OPT_Wc__11_extensions,
+ pedwarn (loc, OPT_Wc__11_extensions,
"ref-qualifiers "
"only available with %<-std=c++11%> or %<-std=gnu++11%>");
break;
declarator->declarator = NULL;
declarator->parameter_pack_p = false;
declarator->id_loc = UNKNOWN_LOCATION;
+ declarator->init_loc = UNKNOWN_LOCATION;
return declarator;
}
attributes, prefix_attributes,
&pushed_scope);
+ declarator->init_loc = cp_lexer_peek_token (parser->lexer)->location;
/* Parse the initializer. */
if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
{
{
is_initialized = SD_INITIALIZED;
initialization_kind = token->type;
+ declarator->init_loc = token->location;
if (maybe_range_for_decl)
*maybe_range_for_decl = error_mark_node;
tmp_init_loc = token->location;
{
tree type = decl_specifiers.type;
token = cp_lexer_peek_token (parser->lexer);
+ if (declarator)
+ declarator->init_loc = token->location;
/* If we are defining a class, then the tokens that make up the
default argument must be saved and processed later. */
if (!template_parm_p && at_class_scope_p ()
constant-initializer. When we call `grokfield', it will
perform more stringent semantics checks. */
initializer_token_start = cp_lexer_peek_token (parser->lexer);
+ declarator->init_loc = initializer_token_start->location;
if (function_declarator_p (declarator)
|| (decl_specifiers.type
&& TREE_CODE (decl_specifiers.type) == TYPE_DECL
&& !function_declarator_p (declarator))
{
bool x;
+ declarator->init_loc
+ = cp_lexer_peek_token (parser->lexer)->location;
if (decl_specifiers.storage_class != sc_static)
initializer = cp_parser_save_nsdmi (parser);
else