Skip to content

Commit 7968107

Browse files
committed
[master] auto linkage can only be used inside a function.
1 parent 8c0bbe9 commit 7968107

16 files changed

+32
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ src/latex
3434
core
3535
*.core
3636
callgrind.out.*
37+
tags

src/dale/ErrorType/ErrorType.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,10 @@ const char *errorInstanceToString(int error_instance) {
440440
"must have constant initialiser for function-scoped "
441441
"intern variable";
442442
break;
443+
case ErrorInst::AutoLinkageNotPermitted:
444+
ret =
445+
"auto linkage not permitted outside of function scope";
446+
break;
443447
default:
444448
ret = "(Unknown)";
445449
}

src/dale/ErrorType/ErrorType.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ enum {
121121
CTOFromNonCTO,
122122
CTOAddrFromNonCTO,
123123
CTOAnonymousFromNonCTO,
124+
AutoLinkageNotPermitted,
124125

125126
DNodeHasNoString,
126127
DNodeIsNeitherTokenNorList,

src/dale/Form/TopLevel/GlobalVariable/GlobalVariable.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ bool FormTopLevelGlobalVariableParse(Units *units, Node *node,
8484
}
8585

8686
int linkage = FormLinkageParse(ctx, linkage_node);
87+
if (linkage == Linkage::Auto) {
88+
Error *e =
89+
new Error(AutoLinkageNotPermitted, linkage_node);
90+
ctx->er->addError(e);
91+
return false;
92+
}
8793

8894
Type *ret_type = FormTypeParse(units, type_node, false, false);
8995
if (ret_type == NULL) {

t/999last/001compile-errors.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ $ENV{"DALE_TEST_ARGS"} ||= "";
66
my $test_dir = $ENV{"DALE_TEST_DIR"} || ".";
77
$ENV{PATH} .= ":.";
88

9-
use Test::More tests => 324;
9+
use Test::More tests => 327;
1010

1111
my @error_files =
1212
(@ARGV)

t/error-src/auto-linkage.dt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(def v1 (var auto int 100))
2+
3+
(namespace n
4+
(def v2 (var auto int 100)))

t/error-src/auto-linkage.dt.errors

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
t/error-src/auto-linkage.dt:1:14: error: auto linkage not permitted outside of function scope
2+
t/error-src/auto-linkage.dt:4:16: error: auto linkage not permitted outside of function scope

t/error-src/unsupported-literal.dt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
(namespace temp3
77
(def mys (struct extern ((# int)))))))
88

9-
(def n (var auto mys 100.0))
10-
(def n (var auto temp.temp2.temp3.mys 100.0))
11-
(def n (var auto temp.mys 100.0))
9+
(def n (var intern mys 100.0))
10+
(def n (var intern temp.temp2.temp3.mys 100.0))
11+
(def n (var intern temp.mys 100.0))
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
./t/error-src/unsupported-literal.dt:9:22: error: expected return expression with type mys (got type float instead)
2-
./t/error-src/unsupported-literal.dt:10:39: error: expected return expression with type temp.temp2.temp3.mys (got type float instead)
3-
./t/error-src/unsupported-literal.dt:11:27: error: expected return expression with type temp.mys (got type float instead)
1+
./t/error-src/unsupported-literal.dt:9:24: error: expected return expression with type mys (got type float instead)
2+
./t/error-src/unsupported-literal.dt:10:41: error: expected return expression with type temp.temp2.temp3.mys (got type float instead)
3+
./t/error-src/unsupported-literal.dt:11:29: error: expected return expression with type temp.mys (got type float instead)

t/src/const-global.dt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(import cstdio)
22

3-
(def n (var auto (const int) 100))
3+
(def n (var intern (const int) 100))
44

55
(def main (fn extern-c int (void)
66
(printf "%d\n" n)

0 commit comments

Comments
 (0)