1/* Process declarations and variables for C++ compiler. 2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 3 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. 4 Contributed by Michael Tiemann (tiemann@cygnus.com) 5 6This file is part of GCC. 7 8GCC is free software; you can redistribute it and/or modify --- 1366 unchanged lines hidden (view full) --- 1375 TYPE_ARG_TYPES (TREE_TYPE (olddecl)))) 1376 { 1377 error ("new declaration `%#D'", newdecl); 1378 cp_error_at ("ambiguates old declaration `%#D'", olddecl); 1379 } 1380 else 1381 return NULL_TREE; 1382 } |
1383 else |
1384 { 1385 error ("conflicting declaration '%#D'", newdecl); 1386 cp_error_at ("'%D' has a previous declaration as `%#D'", 1387 olddecl, olddecl); 1388 return NULL_TREE; 1389 } 1390 } 1391 else if (TREE_CODE (newdecl) == FUNCTION_DECL --- 1247 unchanged lines hidden (view full) --- 2639 name = TREE_OPERAND (fullname, 0) = DECL_NAME (name); 2640 } 2641 if (TREE_CODE (name) == TEMPLATE_DECL) 2642 { 2643 error ("`%D' used without template parameters", name); 2644 return error_mark_node; 2645 } 2646 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 20030802); |
2647 my_friendly_assert (TYPE_P (context), 20050905); |
2648 2649 if (!dependent_type_p (context) 2650 || currently_open_class (context)) 2651 { 2652 if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR) 2653 { 2654 tree tmpl = NULL_TREE; 2655 if (IS_AGGR_TYPE (context)) --- 2246 unchanged lines hidden (view full) --- 4902 init = check_initializer (decl, init, flags, &cleanup); 4903 /* Thread-local storage cannot be dynamically initialized. */ 4904 if (DECL_THREAD_LOCAL (decl) && init) 4905 { 4906 error ("`%D' is thread-local and so cannot be dynamically " 4907 "initialized", decl); 4908 init = NULL_TREE; 4909 } |
4910 if (DECL_EXTERNAL (decl) && init) 4911 { 4912 /* The static data member cannot be initialized by a 4913 non-constant when being declared. */ 4914 error ("`%D' cannot be initialized by a non-constant expression" 4915 " when being declared", decl); 4916 DECL_INITIALIZED_IN_CLASS_P (decl) = 0; 4917 init = NULL_TREE; 4918 } 4919 |
4920 /* Handle: 4921 4922 [dcl.init] 4923 4924 The memory occupied by any object of static storage 4925 duration is zero-initialized at program startup before 4926 any other initialization takes place. 4927 --- 783 unchanged lines hidden (view full) --- 5711 if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE) 5712 { 5713 error ("%smember function `%D' cannot have `%T' method qualifier", 5714 (ctype ? "static " : "non-"), decl, TREE_VALUE (quals)); 5715 quals = NULL_TREE; 5716 } 5717 5718 if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))) |
5719 grok_op_properties (decl, /*complain=*/true); |
5720 5721 if (ctype && decl_function_context (decl)) 5722 DECL_NO_STATIC_CHAIN (decl) = 1; 5723 5724 for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t)) 5725 if (TREE_PURPOSE (t) 5726 && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG) 5727 { --- 158 unchanged lines hidden (view full) --- 5886grokvardecl (tree type, 5887 tree name, 5888 RID_BIT_TYPE * specbits_in, 5889 int initialized, 5890 int constp, 5891 tree scope) 5892{ 5893 tree decl; |
5894 tree explicit_scope; |
5895 RID_BIT_TYPE specbits; 5896 5897 my_friendly_assert (!name || TREE_CODE (name) == IDENTIFIER_NODE, 5898 20020808); 5899 5900 specbits = *specbits_in; 5901 |
5902 /* Compute the scope in which to place the variable, but remember 5903 whether or not that scope was explicitly specified by the user. */ 5904 explicit_scope = scope; |
5905 if (!scope) 5906 { 5907 /* An explicit "extern" specifier indicates a namespace-scope 5908 variable. */ 5909 if (RIDBIT_SETP (RID_EXTERN, specbits)) 5910 scope = current_namespace; 5911 else if (!at_function_scope_p ()) 5912 { --- 12 unchanged lines hidden (view full) --- 5925 || (TREE_CODE (scope) == NAMESPACE_DECL 5926 && current_lang_name != lang_name_cplusplus) 5927 /* Similarly for static data members. */ 5928 || TYPE_P (scope))) 5929 decl = build_lang_decl (VAR_DECL, name, type); 5930 else 5931 decl = build_decl (VAR_DECL, name, type); 5932 |
5933 if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL) 5934 set_decl_namespace (decl, explicit_scope, 0); |
5935 else 5936 DECL_CONTEXT (decl) = scope; 5937 5938 if (name && scope && current_lang_name != lang_name_c) 5939 /* We can't mangle lazily here because we don't have any 5940 way to recover whether or not a variable was `extern 5941 "C"' later. */ 5942 mangle_decl (decl); --- 1240 unchanged lines hidden (view full) --- 7183 explicitp = RIDBIT_SETP (RID_EXPLICIT, specbits) != 0; 7184 RIDBIT_RESET (RID_EXPLICIT, specbits); 7185 7186 if (RIDBIT_SETP (RID_STATIC, specbits)) 7187 staticp = 1 + (decl_context == FIELD); 7188 7189 if (virtualp && staticp == 2) 7190 { |
7191 error ("member `%D' cannot be declared both virtual and static", dname); 7192 RIDBIT_RESET (RID_STATIC, specbits); |
7193 staticp = 0; 7194 } 7195 friendp = RIDBIT_SETP (RID_FRIEND, specbits); 7196 RIDBIT_RESET (RID_FRIEND, specbits); 7197 7198 if (dependant_name && !friendp) 7199 { 7200 error ("`%T::%D' is not a valid declarator", ctype, dependant_name); --- 1799 unchanged lines hidden (view full) --- 9000 || code == TYPE_EXPR); 9001} 9002 9003/* DECL is a declaration for an overloaded operator. Returns true if 9004 the declaration is valid; false otherwise. If COMPLAIN is true, 9005 errors are issued for invalid declarations. */ 9006 9007bool |
9008grok_op_properties (tree decl, bool complain) |
9009{ 9010 tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl)); 9011 tree argtype; 9012 int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE); 9013 tree name = DECL_NAME (decl); 9014 enum tree_code operator_code; 9015 int arity; |
9016 bool ellipsis_p; |
9017 bool ok; |
9018 tree class_type; |
9019 9020 /* Assume that the declaration is valid. */ 9021 ok = true; 9022 |
9023 /* Count the number of arguments. and check for ellipsis */ |
9024 for (argtype = argtypes, arity = 0; 9025 argtype && argtype != void_list_node; 9026 argtype = TREE_CHAIN (argtype)) 9027 ++arity; |
9028 ellipsis_p = !argtype; |
9029 |
9030 class_type = DECL_CONTEXT (decl); 9031 if (class_type && !CLASS_TYPE_P (class_type)) 9032 class_type = NULL_TREE; 9033 |
9034 if (DECL_CONV_FN_P (decl)) 9035 operator_code = TYPE_EXPR; 9036 else 9037 do 9038 { 9039#define DEF_OPERATOR(NAME, CODE, MANGLING, ARITY, ASSN_P) \ 9040 if (ansi_opname (CODE) == name) \ 9041 { \ --- 11 unchanged lines hidden (view full) --- 9053#undef DEF_OPERATOR 9054 9055 abort (); 9056 } 9057 while (0); 9058 my_friendly_assert (operator_code != LAST_CPLUS_TREE_CODE, 20000526); 9059 SET_OVERLOADED_OPERATOR_CODE (decl, operator_code); 9060 |
9061 if (class_type) 9062 switch (operator_code) 9063 { 9064 case NEW_EXPR: 9065 TYPE_HAS_NEW_OPERATOR (class_type) = 1; 9066 break; |
9067 |
9068 case DELETE_EXPR: 9069 TYPE_GETS_DELETE (class_type) |= 1; 9070 break; |
9071 |
9072 case VEC_NEW_EXPR: 9073 TYPE_HAS_ARRAY_NEW_OPERATOR (class_type) = 1; 9074 break; |
9075 |
9076 case VEC_DELETE_EXPR: 9077 TYPE_GETS_DELETE (class_type) |= 2; 9078 break; |
9079 |
9080 default: 9081 break; 9082 } |
9083 9084 if (operator_code == NEW_EXPR || operator_code == VEC_NEW_EXPR) 9085 TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl)); 9086 else if (operator_code == DELETE_EXPR || operator_code == VEC_DELETE_EXPR) 9087 TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl)); 9088 else 9089 { 9090 /* An operator function must either be a non-static member function --- 37 unchanged lines hidden (view full) --- 9128 } 9129 } 9130 9131 /* There are no restrictions on the arguments to an overloaded 9132 "operator ()". */ 9133 if (operator_code == CALL_EXPR) 9134 return ok; 9135 |
9136 /* Warn about conversion operators that will never be used. */ 9137 if (IDENTIFIER_TYPENAME_P (name) 9138 && ! DECL_TEMPLATE_INFO (decl) 9139 && warn_conversion 9140 /* Warn only declaring the function; there is no need to 9141 warn again about out-of-class definitions. */ 9142 && class_type == current_class_type) |
9143 { 9144 tree t = TREE_TYPE (name); |
9145 int ref = (TREE_CODE (t) == REFERENCE_TYPE); 9146 const char *what = 0; 9147 9148 if (ref) 9149 t = TYPE_MAIN_VARIANT (TREE_TYPE (t)); 9150 9151 if (TREE_CODE (t) == VOID_TYPE) 9152 what = "void"; 9153 else if (class_type) |
9154 { |
9155 if (t == class_type) |
9156 what = "the same type"; 9157 /* Don't force t to be complete here. */ 9158 else if (IS_AGGR_TYPE (t) 9159 && COMPLETE_TYPE_P (t) |
9160 && DERIVED_FROM_P (t, class_type)) |
9161 what = "a base class"; |
9162 } |
9163 9164 if (what) 9165 warning ("conversion to %s%s will never use a type conversion operator", 9166 ref ? "a reference to " : "", what); |
9167 } |
9168 |
9169 if (operator_code == COND_EXPR) 9170 { 9171 /* 13.4.0.3 */ 9172 error ("ISO C++ prohibits overloading operator ?:"); 9173 } |
9174 else if (ellipsis_p) 9175 error ("`%D' must not have variable number of arguments", decl); |
9176 else if (ambi_op_p (operator_code)) 9177 { 9178 if (arity == 1) 9179 /* We pick the one-argument operator codes by default, so 9180 we don't have to change anything. */ 9181 ; 9182 else if (arity == 2) 9183 { --- 148 unchanged lines hidden (view full) --- 9332{ 9333 switch (code) 9334 { 9335 case record_type: 9336 return "struct"; 9337 case class_type: 9338 return "class"; 9339 case union_type: |
9340 return "union"; |
9341 case enum_type: 9342 return "enum"; |
9343 case typename_type: 9344 return "typename"; |
9345 default: 9346 abort (); 9347 } 9348} 9349 9350/* Name lookup in an elaborated-type-specifier (after the keyword 9351 indicated by TAG_CODE) has found the TYPE_DECL DECL. If the 9352 elaborated-type-specifier is invalid, issue a diagnostic and return --- 21 unchanged lines hidden (view full) --- 9374 /* [dcl.type.elab] 9375 9376 If the identifier resolves to a typedef-name or a template 9377 type-parameter, the elaborated-type-specifier is ill-formed. 9378 9379 In other words, the only legitimate declaration to use in the 9380 elaborated type specifier is the implicit typedef created when 9381 the type is declared. */ |
9382 if (!DECL_IMPLICIT_TYPEDEF_P (decl) 9383 && tag_code != typename_type) |
9384 { 9385 error ("using typedef-name `%D' after `%s'", decl, tag_name (tag_code)); 9386 return IS_AGGR_TYPE (type) ? type : error_mark_node; 9387 } 9388 9389 if (TREE_CODE (type) == TEMPLATE_TYPE_PARM) 9390 { 9391 error ("using template type parameter `%T' after `%s'", 9392 type, tag_name (tag_code)); 9393 return error_mark_node; 9394 } 9395 else if (TREE_CODE (type) != RECORD_TYPE 9396 && TREE_CODE (type) != UNION_TYPE |
9397 && tag_code != enum_type 9398 && tag_code != typename_type) |
9399 { 9400 error ("`%T' referred to as `%s'", type, tag_name (tag_code)); 9401 return error_mark_node; 9402 } 9403 else if (TREE_CODE (type) != ENUMERAL_TYPE 9404 && tag_code == enum_type) 9405 { 9406 error ("`%T' referred to as enum", type); --- 905 unchanged lines hidden (view full) --- 10312 (This does not mean `static' in the C sense!) */ 10313 TREE_STATIC (decl1) = 1; 10314 10315 /* We must call push_template_decl after current_class_type is set 10316 up. (If we are processing inline definitions after exiting a 10317 class scope, current_class_type will be NULL_TREE until set above 10318 by push_nested_class.) */ 10319 if (processing_template_decl) |
10320 { 10321 tree newdecl1 = push_template_decl (decl1); 10322 if (newdecl1 != error_mark_node) 10323 decl1 = newdecl1; 10324 } |
10325 10326 /* We are now in the scope of the function being defined. */ 10327 current_function_decl = decl1; 10328 10329 /* Save the parm names or decls from this function's declarator 10330 where store_parm_decls will find them. */ 10331 current_function_parms = DECL_ARGUMENTS (decl1); 10332 10333 /* Make sure the parameter and return types are reasonable. When 10334 you declare a function, these types can be incomplete, but they 10335 must be complete when you define the function. */ 10336 if (! processing_template_decl) 10337 check_function_type (decl1, current_function_parms); |
10338 /* Make sure no default arg is missing. */ 10339 check_default_args (decl1); |
10340 10341 /* Build the return declaration for the function. */ 10342 restype = TREE_TYPE (fntype); 10343 /* Promote the value to int before returning it. */ 10344 if (c_promoting_integer_type_p (restype)) 10345 restype = type_promotes_to (restype); 10346 if (DECL_RESULT (decl1) == NULL_TREE) 10347 { --- 47 unchanged lines hidden (view full) --- 10395 the same function or DECL1 itself. */ 10396 decl1 = olddecl; 10397 } 10398 else 10399 { 10400 /* We need to set the DECL_CONTEXT. */ 10401 if (!DECL_CONTEXT (decl1) && DECL_TEMPLATE_INFO (decl1)) 10402 DECL_CONTEXT (decl1) = DECL_CONTEXT (DECL_TI_TEMPLATE (decl1)); |
10403 } 10404 fntype = TREE_TYPE (decl1); 10405 } 10406 10407 /* Reset these in case the call to pushdecl changed them. */ 10408 current_function_decl = decl1; 10409 cfun->decl = decl1; 10410 --- 960 unchanged lines hidden --- |