From ad67c1977e250bc6f787b0ecf93cb96a200f753f Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Mon, 7 Jul 2014 19:43:02 +0200 Subject: [PATCH 1/4] Explicitely specify C and C++ standards to use This does not change anything, it just makes the defaults explicit. --- hardware/arduino/avr/platform.txt | 4 ++-- hardware/arduino/sam/platform.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hardware/arduino/avr/platform.txt b/hardware/arduino/avr/platform.txt index b3c99864c5c..e451b43aecc 100644 --- a/hardware/arduino/avr/platform.txt +++ b/hardware/arduino/avr/platform.txt @@ -20,14 +20,14 @@ compiler.warning_flags.all=-Wall -Wextra # Default "compiler.path" is correct, change only if you want to overidde the initial value compiler.path={runtime.tools.avr-gcc.path}/bin/ compiler.c.cmd=avr-gcc -compiler.c.flags=-c -g -Os {compiler.warning_flags} -ffunction-sections -fdata-sections -MMD +compiler.c.flags=-c -g -Os {compiler.warning_flags} -std=gnu89 -ffunction-sections -fdata-sections -MMD # -w flag added to avoid printing a wrong warning http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59396 # This is fixed in gcc 4.8.3 and will be removed as soon as we update the toolchain compiler.c.elf.flags={compiler.warning_flags} -Os -Wl,--gc-sections compiler.c.elf.cmd=avr-gcc compiler.S.flags=-c -g -x assembler-with-cpp compiler.cpp.cmd=avr-g++ -compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD +compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++98 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD compiler.ar.cmd=avr-ar compiler.ar.flags=rcs compiler.objcopy.cmd=avr-objcopy diff --git a/hardware/arduino/sam/platform.txt b/hardware/arduino/sam/platform.txt index d52fb98a408..7149cbf16be 100644 --- a/hardware/arduino/sam/platform.txt +++ b/hardware/arduino/sam/platform.txt @@ -19,13 +19,13 @@ compiler.warning_flags.all=-Wall -Wextra compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/ compiler.c.cmd=arm-none-eabi-gcc -compiler.c.flags=-c -g -Os {compiler.warning_flags} -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -Dprintf=iprintf -MMD +compiler.c.flags=-c -g -Os {compiler.warning_flags} -std=gnu89 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -Dprintf=iprintf -MMD compiler.c.elf.cmd=arm-none-eabi-gcc compiler.c.elf.flags=-Os -Wl,--gc-sections compiler.S.cmd=arm-none-eabi-gcc compiler.S.flags=-c -g -x assembler-with-cpp -mthumb compiler.cpp.cmd=arm-none-eabi-g++ -compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf -MMD +compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++98 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf -MMD compiler.ar.cmd=arm-none-eabi-ar compiler.ar.flags=rcs compiler.objcopy.cmd=arm-none-eabi-objcopy From 2f032fb1413bcaf1f4f4b1cd082a9a32acd3b63e Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Mon, 7 Jul 2014 19:43:51 +0200 Subject: [PATCH 2/4] Enable C++11 support This uses the gnu++11 standard, which is C++11 with GNU extensions. C++11 should be full compatible with the previously used C++98 standards, so all pre-existing sketches should continue to work. --- hardware/arduino/avr/platform.txt | 2 +- hardware/arduino/sam/platform.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hardware/arduino/avr/platform.txt b/hardware/arduino/avr/platform.txt index e451b43aecc..e3f13494c6f 100644 --- a/hardware/arduino/avr/platform.txt +++ b/hardware/arduino/avr/platform.txt @@ -27,7 +27,7 @@ compiler.c.elf.flags={compiler.warning_flags} -Os -Wl,--gc-sections compiler.c.elf.cmd=avr-gcc compiler.S.flags=-c -g -x assembler-with-cpp compiler.cpp.cmd=avr-g++ -compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++98 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD +compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD compiler.ar.cmd=avr-ar compiler.ar.flags=rcs compiler.objcopy.cmd=avr-objcopy diff --git a/hardware/arduino/sam/platform.txt b/hardware/arduino/sam/platform.txt index 7149cbf16be..93f3339fa58 100644 --- a/hardware/arduino/sam/platform.txt +++ b/hardware/arduino/sam/platform.txt @@ -25,7 +25,7 @@ compiler.c.elf.flags=-Os -Wl,--gc-sections compiler.S.cmd=arm-none-eabi-gcc compiler.S.flags=-c -g -x assembler-with-cpp -mthumb compiler.cpp.cmd=arm-none-eabi-g++ -compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++98 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf -MMD +compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf -MMD compiler.ar.cmd=arm-none-eabi-ar compiler.ar.flags=rcs compiler.objcopy.cmd=arm-none-eabi-objcopy From c98c226963ab00692f1691bcef1ce55c799924fc Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Mon, 7 Jul 2014 19:54:31 +0200 Subject: [PATCH 3/4] Check for __cplusplus >= 201103L as well as __GXX_EXPERIMENTAL_CXX0X__ Gcc 4.8 defines __cplusplus as 201103L, so we can check for that now. It still also defines __GXX_EXPERIMENTAL_CXX0X__, but this could help on other compilers, or if gcc ever decides to stop defining the experimental macro. --- hardware/arduino/avr/cores/arduino/WString.cpp | 6 +++--- hardware/arduino/avr/cores/arduino/WString.h | 6 +++--- hardware/arduino/sam/cores/arduino/WString.cpp | 6 +++--- hardware/arduino/sam/cores/arduino/WString.h | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/WString.cpp b/hardware/arduino/avr/cores/arduino/WString.cpp index dcd469d7dd0..cd3e0e876d0 100644 --- a/hardware/arduino/avr/cores/arduino/WString.cpp +++ b/hardware/arduino/avr/cores/arduino/WString.cpp @@ -43,7 +43,7 @@ String::String(const __FlashStringHelper *pstr) *this = pstr; } -#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String::String(String &&rval) { init(); @@ -189,7 +189,7 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length) return *this; } -#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) void String::move(String &rhs) { if (buffer) { @@ -221,7 +221,7 @@ String & String::operator = (const String &rhs) return *this; } -#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String & String::operator = (String &&rval) { if (this != &rval) move(rval); diff --git a/hardware/arduino/avr/cores/arduino/WString.h b/hardware/arduino/avr/cores/arduino/WString.h index 74024309278..b047980877c 100644 --- a/hardware/arduino/avr/cores/arduino/WString.h +++ b/hardware/arduino/avr/cores/arduino/WString.h @@ -59,7 +59,7 @@ class String String(const char *cstr = ""); String(const String &str); String(const __FlashStringHelper *str); - #ifdef __GXX_EXPERIMENTAL_CXX0X__ + #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String(String &&rval); String(StringSumHelper &&rval); #endif @@ -86,7 +86,7 @@ class String String & operator = (const String &rhs); String & operator = (const char *cstr); String & operator = (const __FlashStringHelper *str); - #ifdef __GXX_EXPERIMENTAL_CXX0X__ + #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String & operator = (String &&rval); String & operator = (StringSumHelper &&rval); #endif @@ -200,7 +200,7 @@ class String // copy and move String & copy(const char *cstr, unsigned int length); String & copy(const __FlashStringHelper *pstr, unsigned int length); - #ifdef __GXX_EXPERIMENTAL_CXX0X__ + #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) void move(String &rhs); #endif }; diff --git a/hardware/arduino/sam/cores/arduino/WString.cpp b/hardware/arduino/sam/cores/arduino/WString.cpp index 53f16cdc051..e1d60f471fa 100644 --- a/hardware/arduino/sam/cores/arduino/WString.cpp +++ b/hardware/arduino/sam/cores/arduino/WString.cpp @@ -45,7 +45,7 @@ String::String(const __FlashStringHelper *pstr) *this = pstr; } -#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String::String(String &&rval) { init(); @@ -191,7 +191,7 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length) return *this; } -#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) void String::move(String &rhs) { if (buffer) { @@ -223,7 +223,7 @@ String & String::operator = (const String &rhs) return *this; } -#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String & String::operator = (String &&rval) { if (this != &rval) move(rval); diff --git a/hardware/arduino/sam/cores/arduino/WString.h b/hardware/arduino/sam/cores/arduino/WString.h index 74024309278..b047980877c 100644 --- a/hardware/arduino/sam/cores/arduino/WString.h +++ b/hardware/arduino/sam/cores/arduino/WString.h @@ -59,7 +59,7 @@ class String String(const char *cstr = ""); String(const String &str); String(const __FlashStringHelper *str); - #ifdef __GXX_EXPERIMENTAL_CXX0X__ + #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String(String &&rval); String(StringSumHelper &&rval); #endif @@ -86,7 +86,7 @@ class String String & operator = (const String &rhs); String & operator = (const char *cstr); String & operator = (const __FlashStringHelper *str); - #ifdef __GXX_EXPERIMENTAL_CXX0X__ + #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String & operator = (String &&rval); String & operator = (StringSumHelper &&rval); #endif @@ -200,7 +200,7 @@ class String // copy and move String & copy(const char *cstr, unsigned int length); String & copy(const __FlashStringHelper *pstr, unsigned int length); - #ifdef __GXX_EXPERIMENTAL_CXX0X__ + #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) void move(String &rhs); #endif }; From 4abf6e4ea488405ed31ef8daca32ac19abac96e2 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Mon, 7 Jul 2014 19:43:51 +0200 Subject: [PATCH 4/4] Enable C11 support This uses the gnu11 standard, which is C11 with GNU extensions. Previously, gnu89 was being used, which is pretty ancient by now. C99 brings some important improvements, some of which were already available and used even without this option. C11 is more recent and brings more minor improvements. Most notable feature is the static_assert statement, allowing checking invariants at compiletime using the full C expressions. --- hardware/arduino/avr/platform.txt | 2 +- hardware/arduino/sam/platform.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hardware/arduino/avr/platform.txt b/hardware/arduino/avr/platform.txt index e3f13494c6f..5d6c327e77c 100644 --- a/hardware/arduino/avr/platform.txt +++ b/hardware/arduino/avr/platform.txt @@ -20,7 +20,7 @@ compiler.warning_flags.all=-Wall -Wextra # Default "compiler.path" is correct, change only if you want to overidde the initial value compiler.path={runtime.tools.avr-gcc.path}/bin/ compiler.c.cmd=avr-gcc -compiler.c.flags=-c -g -Os {compiler.warning_flags} -std=gnu89 -ffunction-sections -fdata-sections -MMD +compiler.c.flags=-c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -MMD # -w flag added to avoid printing a wrong warning http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59396 # This is fixed in gcc 4.8.3 and will be removed as soon as we update the toolchain compiler.c.elf.flags={compiler.warning_flags} -Os -Wl,--gc-sections diff --git a/hardware/arduino/sam/platform.txt b/hardware/arduino/sam/platform.txt index 93f3339fa58..6f9970df1b2 100644 --- a/hardware/arduino/sam/platform.txt +++ b/hardware/arduino/sam/platform.txt @@ -19,7 +19,7 @@ compiler.warning_flags.all=-Wall -Wextra compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/ compiler.c.cmd=arm-none-eabi-gcc -compiler.c.flags=-c -g -Os {compiler.warning_flags} -std=gnu89 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -Dprintf=iprintf -MMD +compiler.c.flags=-c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -Dprintf=iprintf -MMD compiler.c.elf.cmd=arm-none-eabi-gcc compiler.c.elf.flags=-Os -Wl,--gc-sections compiler.S.cmd=arm-none-eabi-gcc