Skip to content

Commit ab7762e

Browse files
author
Pascal Beyer
committed
Fix an assert when trying to __declspec(dllimport) something inside of a function. It now prints a bad error instead.
1 parent 366bcd5 commit ab7762e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/parse.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7677,6 +7677,11 @@ func struct declaration_list parse_declaration_list(struct context *context, str
76777677
// We check that this declaration is actually contained in some dll only for the ones
76787678
// we actually use. This is done in 'explain.c'.
76797679
function->as_decl.flags |= DECLARATION_FLAGS_is_dllimport;
7680+
7681+
if(context->current_scope){
7682+
// @incomplete: For now disallow __declspec(dllimport) at local scope.
7683+
report_error(context, function->base.token, "@incomplete: Currently, __declspec(dllimport) is not allowed inside a function.");
7684+
}
76807685
}
76817686

76827687
if(specifiers.specifier_flags & SPECIFIER_printlike){
@@ -7858,6 +7863,11 @@ func struct declaration_list parse_declaration_list(struct context *context, str
78587863
if(maybe_resolve_unresolved_type_or_sleep_or_error(context, &decl->type)) goto end;
78597864
}
78607865

7866+
if(context->current_scope && specifiers.specifier_flags & SPECIFIER_dllimport){
7867+
// @incomplete: For now disallow __declspec(dllimport) at local scope.
7868+
report_error(context, decl->base.token, "@incomplete: Currently, __declspec(dllimport) is not allowed inside a function.");
7869+
}
7870+
78617871
//
78627872
// Register it up here already in case of 'void *asd = &asd;'
78637873
// this means that for right now the declaration is 'not initialized' even if it has an

tests/error/dllimport_and_dllexport_at_local_scope.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// reject "Error at 'extern_initialized_dllimport_variable'"
77
// reject "Error at 'extern_initialized_dllexport_variable'"
88
// fail
9+
// broken
910

1011
int main(){
1112
static __declspec(dllimport) int static_uninitialized_dllimport_variable; // Error: cannot be static

0 commit comments

Comments
 (0)