aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJukka Jylänki <jujjyl@gmail.com>2013-02-01 22:48:09 +0200
committerJukka Jylänki <jujjyl@gmail.com>2013-02-01 22:51:35 +0200
commit9dd7e94ecd16a6b4200a276880f378c3e155c212 (patch)
tree659019ba2d0c3f2c8e23f6440071c55acdb8de36
parentc40babef1f7774dde1a7eaa16fddc59929539481 (diff)
Compile with -std=c++03 consistently on all platforms. By default, Clang 3.2 inconsistently uses C++11 for Windows and C++03 for Linux if user did not specify -std= on the command line. Fixes other.test_embind and *.test_llvmswitch. Add unit tests that confirm that .cpp files are compiled with C++03 std by default.
-rwxr-xr-xemcc14
-rw-r--r--tests/hello_cxx03.cpp10
-rwxr-xr-xtests/runner.py10
3 files changed, 31 insertions, 3 deletions
diff --git a/emcc b/emcc
index 73f12cda..f21feb1f 100755
--- a/emcc
+++ b/emcc
@@ -596,6 +596,10 @@ try:
keep_debug = False
bind = False
jcache = False
+ if use_cxx:
+ default_cxx_std = '-std=c++03' # Enforce a consistent C++ standard when compiling .cpp files, if user does not specify one on the cmdline.
+ else:
+ default_cxx_std = '' # Compiling C code with .c files, don't enforce a default C++ std.
def check_bad_eq(arg):
assert '=' not in arg, 'Invalid parameter (do not use "=" with "--" options)'
@@ -659,7 +663,11 @@ try:
keep_debug = True
elif newargs[i] == '--bind':
bind = True
- newargs[i] = '-std=c++11' # Force C++11 for embind code
+ newargs[i] = ''
+ if default_cxx_std:
+ default_cxx_std = '-std=c++11' # Force C++11 for embind code, but only if user has not explicitly overridden a standard.
+ elif newargs[i].startswith('-std='):
+ default_cxx_std = '' # User specified a standard to use, clear Emscripten from specifying it.
elif newargs[i].startswith('--embed-file'):
check_bad_eq(newargs[i])
embed_files.append(newargs[i+1])
@@ -717,6 +725,10 @@ try:
absolute_warning_shown = True
newargs = [ arg for arg in newargs if arg is not '' ]
+ # If user did not specify a default -std for C++ code, specify the emscripten default.
+ if default_cxx_std:
+ newargs = newargs + [default_cxx_std]
+
if llvm_opts is None: llvm_opts = LLVM_OPT_LEVEL[opt_level]
if llvm_lto is None: llvm_lto = llvm_opts > 0
if closure is None: closure = 1 if opt_level >= 2 else 0
diff --git a/tests/hello_cxx03.cpp b/tests/hello_cxx03.cpp
new file mode 100644
index 00000000..d6cc766a
--- /dev/null
+++ b/tests/hello_cxx03.cpp
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+#if __cplusplus != 199711L
+#error By default, if no -std is specified, emscripten should be compiling with -std=c++03!
+#endif
+
+int main( int argc, const char *argv[] ) {
+ printf("Hello world!\\n");
+ return 0;
+}
diff --git a/tests/runner.py b/tests/runner.py
index a22256c3..43a14e7f 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -238,7 +238,7 @@ process(sys.argv[1])
os.remove(f + '.o')
except:
pass
- args = [Building.COMPILER, '-emit-llvm'] + COMPILER_OPTS + Building.COMPILER_TEST_OPTS + \
+ args = [Building.COMPILER, '-emit-llvm', '-std=c++03'] + COMPILER_OPTS + Building.COMPILER_TEST_OPTS + \
['-I', dirname, '-I', os.path.join(dirname, 'include')] + \
map(lambda include: '-I' + include, includes) + \
['-c', f, '-o', f + '.o']
@@ -3517,7 +3517,7 @@ def process(filename):
# i.e. as if "-std=c++03" had been passed on the command line. On Linux with Clang 3.2 this is the case, but on Windows
# with Clang 3.2 -std=c++11 has been chosen as default, because of
# < jrose> clb: it's deliberate, with the idea that for people who don't care about the standard, they should be using the "best" thing we can offer on that platform
- def test_cxx03(self):
+ def test_cxx03_do_run(self):
src = '''
#include <stdio.h>
@@ -8406,6 +8406,12 @@ f.close()
assert process.returncode is not 0, 'Trying to compile a nonexisting file should return with a nonzero error code!'
assert os.path.exists('this_output_file_should_never_exist.js') == False, 'Emcc should not produce an output file when build fails!'
+ def test_cxx03(self):
+ for compiler in [EMCC, EMXX]:
+ process = Popen([PYTHON, compiler, path_from_root('tests', 'hello_cxx03.cpp')], stdout=PIPE, stderr=PIPE)
+ process.communicate()
+ assert process.returncode is 0, 'By default, emscripten should build using -std=c++03!'
+
def test_Os(self):
for opt in ['s', '0']:
output = Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-O' + opt], stdout=PIPE, stderr=PIPE).communicate()