@@ -53,6 +53,9 @@ symbolt &cpp_declarator_convertert::convert(
5353 final_type=declarator.merge_type (declaration_type);
5454 assert (final_type.is_not_nil ());
5555
56+ cpp_storage_spect final_storage_spec = storage_spec;
57+ final_storage_spec |= cpp_storage_spect (final_type);
58+
5659 cpp_template_args_non_tct template_args;
5760
5861 // run resolver on scope
@@ -135,7 +138,7 @@ symbolt &cpp_declarator_convertert::convert(
135138 if (!maybe_symbol && is_friend)
136139 {
137140 symbolt &friend_symbol =
138- convert_new_symbol (storage_spec , member_spec, declarator);
141+ convert_new_symbol (final_storage_spec , member_spec, declarator);
139142 // mark it as weak so that the full declaration can replace the symbol
140143 friend_symbol.is_weak = true ;
141144 return friend_symbol;
@@ -191,7 +194,7 @@ symbolt &cpp_declarator_convertert::convert(
191194 type, declarator.member_initializers ());
192195 }
193196
194- if (!storage_spec .is_extern ())
197+ if (!final_storage_spec .is_extern ())
195198 symbol.is_extern =false ;
196199
197200 // initializer?
@@ -217,10 +220,10 @@ symbolt &cpp_declarator_convertert::convert(
217220 const auto maybe_symbol=
218221 cpp_typecheck.symbol_table .get_writeable (final_identifier);
219222 if (!maybe_symbol)
220- return convert_new_symbol (storage_spec , member_spec, declarator);
223+ return convert_new_symbol (final_storage_spec , member_spec, declarator);
221224 symbolt &symbol=*maybe_symbol;
222225
223- if (!storage_spec .is_extern ())
226+ if (!final_storage_spec .is_extern ())
224227 symbol.is_extern = false ;
225228
226229 if (declarator.get_bool (ID_C_template_case))
@@ -449,6 +452,9 @@ symbolt &cpp_declarator_convertert::convert_new_symbol(
449452 symbol.base_name =base_name;
450453 symbol.value =declarator.value ();
451454 symbol.location =declarator.name ().source_location ();
455+ symbol.is_extern = storage_spec.is_extern ();
456+ symbol.is_parameter = declarator.get_is_parameter ();
457+ symbol.is_weak = storage_spec.is_weak ();
452458 symbol.mode =linkage_spec==ID_auto?ID_cpp:linkage_spec;
453459 symbol.module =cpp_typecheck.module ;
454460 symbol.type =final_type;
@@ -461,49 +467,40 @@ symbolt &cpp_declarator_convertert::convert_new_symbol(
461467 symbol.value .is_not_nil ())
462468 symbol.is_macro =true ;
463469
464- if (member_spec.is_inline ())
465- symbol.type .set (ID_C_inlined, true );
466-
467- if (!symbol.is_type )
470+ if (is_code && !symbol.is_type )
468471 {
469- if (is_code)
470- {
471- // it is a function
472- if (storage_spec.is_static ())
473- symbol.is_file_local =true ;
474- }
475- else
476- {
477- // it is a variable
478- symbol.is_state_var =true ;
479- symbol.is_lvalue = !is_reference (symbol.type ) &&
480- !(symbol.type .get_bool (ID_C_constant) &&
481- is_number (symbol.type ) &&
482- symbol.value .id () == ID_constant);
483-
484- if (cpp_typecheck.cpp_scopes .current_scope ().is_global_scope ())
485- {
486- symbol.is_static_lifetime =true ;
472+ // it is a function
473+ symbol.is_static_lifetime = false ;
474+ symbol.is_thread_local = false ;
487475
488- if (storage_spec.is_extern ())
489- symbol.is_extern =true ;
490- }
491- else
492- {
493- if (storage_spec.is_static ())
494- {
495- symbol.is_static_lifetime =true ;
496- symbol.is_file_local =true ;
497- }
498- else if (storage_spec.is_extern ())
499- {
500- cpp_typecheck.error ().source_location =storage_spec.location ();
501- cpp_typecheck.error () << " external storage not permitted here"
502- << messaget::eom;
503- throw 0 ;
504- }
505- }
506- }
476+ symbol.is_file_local = storage_spec.is_static ();
477+
478+ if (member_spec.is_inline ())
479+ symbol.type .set (ID_C_inlined, true );
480+ }
481+ else
482+ {
483+ symbol.is_lvalue =
484+ !is_reference (symbol.type ) &&
485+ !(symbol.type .get_bool (ID_C_constant) && is_number (symbol.type ) &&
486+ symbol.value .id () == ID_constant);
487+
488+ symbol.is_static_lifetime =
489+ !symbol.is_macro && !symbol.is_type &&
490+ (cpp_typecheck.cpp_scopes .current_scope ().is_global_scope () ||
491+ storage_spec.is_static ());
492+
493+ symbol.is_thread_local =
494+ (!symbol.is_static_lifetime && !storage_spec.is_extern ()) ||
495+ storage_spec.is_thread_local ();
496+
497+ symbol.is_file_local =
498+ symbol.is_macro ||
499+ (!cpp_typecheck.cpp_scopes .current_scope ().is_global_scope () &&
500+ !storage_spec.is_extern ()) ||
501+ (cpp_typecheck.cpp_scopes .current_scope ().is_global_scope () &&
502+ storage_spec.is_static ()) ||
503+ symbol.is_parameter ;
507504 }
508505
509506 if (symbol.is_static_lifetime )
0 commit comments