fmihpc / vlasiator

Vlasiator - ten letters you can count on
https://www.helsinki.fi/en/researchgroups/vlasiator
Other
48 stars 39 forks source link

declaration of ‘void operator delete(void*)’ has a different exception specifier #299

Open nasailja opened 7 years ago

nasailja commented 7 years ago

Trying to compile with gcc 4.8.5:

mpigxx -I/usr/include -L/usr/lib -O3 -funroll-loops -std=c++11 -W -Wall -pedantic -Wno-unused -Wno-unused-parameter -Wno-missing-braces  -fopenmp  -DUSE_JEMALLOC -DJEMALLOC_NO_DEMANGLE -DPROFILE -DNDEBUG -DACC_SEMILAG_PQM -DTRANS_SEMILAG_PPM  -I/u/ihonkone/libraries/phiprof/gcc/4.8.5/include  -I/u/ihonkone/libraries/jemalloc/gcc/4.8.5/include  -DDP  -DSPF -DVEC8F_AGNER  -c memoryallocation.cpp 
memoryallocation.cpp: In function ‘void operator delete(void*)’:
memoryallocation.cpp:52:29: error: declaration of ‘void operator delete(void*)’ has a different exception specifier
 void operator delete(void *p)
                             ^
In file included from /usr/include/c++/4.8.2/ext/new_allocator.h:33:0,
                 from /usr/include/c++/4.8.2/x86_64-redhat-linux/bits/c++allocator.h:33,
                 from /usr/include/c++/4.8.2/bits/allocator.h:46,
                 from /usr/include/c++/4.8.2/string:41,
                 from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8.2/bits/ios_base.h:41,
                 from /usr/include/c++/4.8.2/ios:42,
                 from /usr/include/c++/4.8.2/ostream:38,
                 from /usr/include/c++/4.8.2/iostream:39,
                 from memoryallocation.cpp:24:
/usr/include/c++/4.8.2/new:95:6: error: from previous declaration ‘void operator delete(void*) noexcept (true)’
 void operator delete(void*) _GLIBCXX_USE_NOEXCEPT
      ^
memoryallocation.cpp: In function ‘void operator delete [](void*)’:
memoryallocation.cpp:71:31: error: declaration of ‘void operator delete [](void*)’ has a different exception specifier
 void operator delete[](void *p)
                               ^
In file included from /usr/include/c++/4.8.2/ext/new_allocator.h:33:0,
                 from /usr/include/c++/4.8.2/x86_64-redhat-linux/bits/c++allocator.h:33,
                 from /usr/include/c++/4.8.2/bits/allocator.h:46,
                 from /usr/include/c++/4.8.2/string:41,
                 from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8.2/bits/ios_base.h:41,
                 from /usr/include/c++/4.8.2/ios:42,
                 from /usr/include/c++/4.8.2/ostream:38,
                 from /usr/include/c++/4.8.2/iostream:39,
                 from memoryallocation.cpp:24:
/usr/include/c++/4.8.2/new:97:6: error: from previous declaration ‘void operator delete [](void*) noexcept (true)’
 void operator delete[](void*) _GLIBCXX_USE_NOEXCEPT
      ^

Apparently deletes are noexcept in c++11 (http://en.cppreference.com/w/cpp/memory/new/operator_delete) and adding noexcept to both fixed the issue for me.

nasailja commented 7 years ago

For reference:

diff --git a/memoryallocation.cpp b/memoryallocation.cpp
index 7c4c6fb9..9fff5766 100644
--- a/memoryallocation.cpp
+++ b/memoryallocation.cpp
@@ -49,7 +49,7 @@ void *operator new(size_t size)
 }

 // Global delete using jemalloc
-void operator delete(void *p)
+void operator delete(void *p) noexcept
 {
    je_free(p);
 }
@@ -68,7 +68,7 @@ void *operator new[](size_t size)
 }

 // Global delete[] using jemalloc
-void operator delete[](void *p)
+void operator delete[](void *p) noexcept
 {
    je_free(p);
 }