[libcxx] r337235 - Address "always inline function is not always inlinable" warning with GCC.

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 16 22:48:48 PDT 2018


Author: ericwf
Date: Mon Jul 16 22:48:48 2018
New Revision: 337235

URL: http://llvm.org/viewvc/llvm-project?rev=337235&view=rev
Log:
Address "always inline function is not always inlinable" warning with GCC.

When an always_inline function is used prior to the functions definition,
the compiler may not be able to inline it as requested by the attribute.
GCC flags the `basic_string(CharT const*)` function as one such example.

This patch supresses the warning, and the problem, by moving the
definition of the string constructor to the inline declaration.
This ensures the body is available when it is first ODR used.

Modified:
    libcxx/trunk/include/string

Modified: libcxx/trunk/include/string
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=337235&r1=337234&r2=337235&view=diff
==============================================================================
--- libcxx/trunk/include/string (original)
+++ libcxx/trunk/include/string Mon Jul 16 22:48:48 2018
@@ -807,8 +807,14 @@ public:
 #endif  // _LIBCPP_CXX03_LANG
 
     template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
-        _LIBCPP_INLINE_VISIBILITY
-        basic_string(const _CharT* __s);
+    _LIBCPP_INLINE_VISIBILITY
+    basic_string(const _CharT* __s) {
+      _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
+      __init(__s, traits_type::length(__s));
+#   if _LIBCPP_DEBUG_LEVEL >= 2
+      __get_db()->__insert_c(this);
+#   endif
+    }
 
     template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
         _LIBCPP_INLINE_VISIBILITY
@@ -1774,17 +1780,6 @@ basic_string<_CharT, _Traits, _Allocator
 }
 
 template <class _CharT, class _Traits, class _Allocator>
-template <class>
-basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s)
-{
-    _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
-    __init(__s, traits_type::length(__s));
-#if _LIBCPP_DEBUG_LEVEL >= 2
-    __get_db()->__insert_c(this);
-#endif
-}
-
-template <class _CharT, class _Traits, class _Allocator>
 template <class>
 basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
     : __r_(__second_tag(), __a)




More information about the cfe-commits mailing list