Lack of __attribute__((noreturn)) on Abort causes clang compiles with -Wmissing-noreturn to fail.

304 views
Skip to first unread message

Ian Rogers

unread,
Oct 10, 2014, 2:00:11 PM10/10/14
to googletes...@googlegroups.com
What steps will reproduce the problem?
1. Build a gtest with clang and specify the -Wmissing-noreturn warning with -Werror.
2. The test will fail to compile with:

external/gtest/include/gtest/internal/gtest-port.h:1816:21: error: function 'Abort' could be declared with attribute 'noreturn' [-Werror,-Wmissing-noreturn]
inline void Abort() { abort(); }


What version of Google Test are you using? On what operating system?
Building Android (which has gtest 1.7.0) on a Linux host.

The following is sufficient to fix the problem:

--- a/include/gtest/internal/gtest-port.h
+++ b/include/gtest/internal/gtest-port.h
@@ -1813,6 +1813,7 @@ inline const char* GetEnv(const char* name) {
 // imitation of standard behaviour.
 void Abort();
 #else
+void Abort() __attribute__((noreturn));
 inline void Abort() { abort(); }
 #endif  // GTEST_OS_WINDOWS_MOBILE


Thanks,
Ian

Billy Donahue

unread,
Oct 10, 2014, 8:18:54 PM10/10/14
to Ian Rogers, Google C++ Testing Framework
Okay, but it has to only be done on a GCC compiler that supports that attribute.
The C++11 way to say this is:

   [[noreturn]] void Abort() { abort(); }

Which unfortunately puts the attribute in a different place, making a macro a little tricky.

And we should prefer that where we can.
Microsoft calls it __declspec(noreturn).

If it's worth doing, it's worth doing everywhere and for all the supported compilers.


--

---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages