Skip to content

Commit 37fe42f

Browse files
committed
Address coderrabit comments
1 parent cf6bd6f commit 37fe42f

7 files changed

Lines changed: 52 additions & 4 deletions

File tree

‎src/pending_changes/gh-252-extern-inline-definitions.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ with --c++17:
2525
#include "a.h"
2626
int g2() { return A<int>().f(); } // Linking with a.cpp previously failed.
2727

28+
// c.cpp
29+
#include "a.h"
30+
template struct A<int>;
31+
2832
The same problem affected GNU C89 "extern inline" functions, functions with
2933
the gnu_inline attribute in C99 and later C modes (which lost the "extern"
3034
keyword), and such definitions of functions with an ellipsis (which were not
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
eccp -DTEST_NUMBER=1 --c++17 Test_name.c use.C inst.C
1+
./check_defs -DTEST_NUMBER=1 --c++17 Test_name.c use.C inst.C
22
Test_name.c:
33
use.C:
44
inst.C:
5+
Test_name.o:
6+
use.o:
7+
inst.o: _ZN1AIiE1fEv _ZN1AIiE1gEiz
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
eccp -DTEST_NUMBER=2 --c++17 --g++ Test_name.c use.C inst.C
1+
./check_defs -DTEST_NUMBER=2 --c++17 --g++ Test_name.c use.C inst.C
22
Test_name.c:
33
use.C:
44
inst.C:
5+
Test_name.o:
6+
use.o:
7+
inst.o: _ZN1AIiE1fEv _ZN1AIiE1gEiz
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
eccp -DTEST_NUMBER=3 --c++17 --g++ -tused Test_name.c use.C inst.C
1+
./check_defs -DTEST_NUMBER=3 --c++17 --g++ -tused Test_name.c use.C inst.C
22
Test_name.c:
33
use.C:
44
inst.C:
5+
Test_name.o:
6+
use.o:
7+
inst.o: _ZN1AIiE1fEv _ZN1AIiE1gEiz
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
eccp -DTEST_NUMBER=4 --c++17 --clang Test_name.c use.C inst.C
1+
./check_defs -DTEST_NUMBER=4 --c++17 --clang Test_name.c use.C inst.C
22
Test_name.c:
33
use.C:
44
inst.C:
5+
Test_name.o:
6+
use.o:
7+
inst.o: _ZN1AIiE1fEv _ZN1AIiE1gEiz
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
# Compile each source file to an object file, check that only inst.o (the
3+
# explicit instantiation) defines A<int>::f and A<int>::g, and then link the
4+
# object files.
5+
opts=
6+
objs=
7+
for arg in "$@"; do
8+
case $arg in
9+
*.c | *.C) objs="$objs ${arg%.*}.o" ;;
10+
*) opts="$opts $arg" ;;
11+
esac
12+
done
13+
eccp -c "$@" || exit $?
14+
status=0
15+
for obj in $objs; do
16+
defs=`nm -g --defined-only $obj | grep -o '_ZN1AIiE1[fg]E[a-z]*' | sort`
17+
defs=`echo $defs`
18+
echo $obj: $defs
19+
expected=
20+
if [ $obj = inst.o ]; then
21+
expected="_ZN1AIiE1fEv _ZN1AIiE1gEiz"
22+
fi
23+
if [ "$defs" != "$expected" ]; then
24+
echo "FAIL: Expected '$expected'."
25+
status=1
26+
fi
27+
done
28+
if [ $status -ne 0 ]; then
29+
exit $status
30+
fi
31+
exec eccp $opts $objs

‎tests/tests/regressions/gh-252/test.mft.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//type:rp
22
//options:--c++17:--c++17 --g++:--c++17 --g++ -tused:--c++17 --clang
33
//source_files:a.h use.C inst.C
4+
//script:./check_defs
45
// The members of A<int> are used here and in use.C, but only inst.C may
56
// define them; each object used to contain an external definition.
67
#include "a.h"

0 commit comments

Comments
 (0)