[libcxx] r282349 - Fix missing _LIBCPP_INLINE_VISIBILITY macro on C++03 specific __hash_table function
Author: ericwf Date: Sat Sep 24 23:05:46 2016 New Revision: 282349 URL: http://llvm.org/viewvc/llvm-project?rev=282349&view=rev Log: Fix missing _LIBCPP_INLINE_VISIBILITY macro on C++03 specific __hash_table function Modified: libcxx/trunk/include/__hash_table Modified: libcxx/trunk/include/__hash_table URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__hash_table?rev=282349&r1=282348&r2=282349&view=diff == --- libcxx/trunk/include/__hash_table (original) +++ libcxx/trunk/include/__hash_table Sat Sep 24 23:05:46 2016 @@ -1100,6 +1100,7 @@ public: #else // !defined(_LIBCPP_CXX03_LANG) template +_LIBCPP_INLINE_VISIBILITY pair __emplace_unique_key_args(_Key const&, _Args& __args); iterator __insert_multi(const __container_value_type& __x); @@ -1937,13 +1938,11 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc> #ifndef _LIBCPP_CXX03_LANG template template -_LIBCPP_INLINE_VISIBILITY pair::iterator, bool> __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args) #else template template -_LIBCPP_INLINE_VISIBILITY pair::iterator, bool> __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args& __args) #endif ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24895: [libc++] Remove various C++03 feature test macros
This revision was automatically updated to reflect the committed changes. Closed by commit rL282347: [libc++] Remove various C++03 feature test macros (authored by EricWF). Changed prior to commit: https://reviews.llvm.org/D24895?vs=72411&id=72412#toc Repository: rL LLVM https://reviews.llvm.org/D24895 Files: libcxx/trunk/include/__config libcxx/trunk/include/iterator libcxx/trunk/include/memory libcxx/trunk/include/ratio libcxx/trunk/include/scoped_allocator libcxx/trunk/include/type_traits libcxx/trunk/test/std/containers/associative/map/map.cons/copy.pass.cpp libcxx/trunk/test/std/containers/associative/multimap/multimap.cons/copy.pass.cpp libcxx/trunk/test/std/containers/associative/multiset/multiset.cons/copy.pass.cpp libcxx/trunk/test/std/containers/associative/set/set.cons/copy.pass.cpp libcxx/trunk/test/std/containers/sequences/deque/deque.cons/copy.pass.cpp libcxx/trunk/test/std/containers/sequences/forwardlist/forwardlist.cons/copy.pass.cpp libcxx/trunk/test/std/containers/sequences/list/list.cons/copy.pass.cpp libcxx/trunk/test/std/containers/unord/unord.map/unord.map.cnstr/copy.pass.cpp libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/copy.pass.cpp libcxx/trunk/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy.pass.cpp libcxx/trunk/test/std/containers/unord/unord.set/unord.set.cnstr/copy.pass.cpp libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp libcxx/trunk/test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp libcxx/trunk/test/std/utilities/memory/pointer.traits/rebind.pass.cpp libcxx/trunk/test/support/test_allocator.h Index: libcxx/trunk/test/support/test_allocator.h === --- libcxx/trunk/test/support/test_allocator.h +++ libcxx/trunk/test/support/test_allocator.h @@ -66,7 +66,7 @@ { assert(data_ >= 0); if (time_to_throw >= throw_after) { -#ifndef _LIBCPP_NO_EXCEPTIONS +#ifndef TEST_HAS_NO_EXCEPTIONS throw std::bad_alloc(); #else std::terminate(); @@ -130,7 +130,7 @@ { assert(data_ >= 0); if (time_to_throw >= throw_after) { -#ifndef _LIBCPP_NO_EXCEPTIONS +#ifndef TEST_HAS_NO_EXCEPTIONS throw std::bad_alloc(); #else std::terminate(); @@ -221,10 +221,10 @@ typedef std::true_type propagate_on_container_move_assignment; typedef std::true_type propagate_on_container_swap; -#ifdef _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if TEST_STD_VER < 11 std::size_t max_size() const {return UINT_MAX / sizeof(T);} -#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#endif }; Index: libcxx/trunk/test/std/utilities/memory/pointer.traits/rebind.pass.cpp === --- libcxx/trunk/test/std/utilities/memory/pointer.traits/rebind.pass.cpp +++ libcxx/trunk/test/std/utilities/memory/pointer.traits/rebind.pass.cpp @@ -19,9 +19,11 @@ #include #include +#include "test_macros.h" + int main() { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#if TEST_STD_VER >= 11 static_assert((std::is_same::rebind, double*>::value), ""); #else static_assert((std::is_same::rebind::other, double*>::value), ""); Index: libcxx/trunk/test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp === --- libcxx/trunk/test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp +++ libcxx/trunk/test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp @@ -19,6 +19,8 @@ #include #include +#include "test_macros.h" + template struct ReboundA {}; @@ -63,17 +65,17 @@ int main() { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#if TEST_STD_VER >= 11 static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); -#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#else static_assert((std::is_same >::rebind_traits::other, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_tra
[libcxx] r282347 - [libc++] Remove various C++03 feature test macros
Author: ericwf Date: Sat Sep 24 22:34:28 2016 New Revision: 282347 URL: http://llvm.org/viewvc/llvm-project?rev=282347&view=rev Log: [libc++] Remove various C++03 feature test macros Summary: Libc++ still uses per-feature configuration macros when configuring for C++11. However libc++ requires a feature-complete C++11 compiler so there is no reason to check individual features. This patch starts the process of removing the feature specific macros and replacing their usage with `_LIBCPP_CXX03_LANG`. This patch removes the __config macros: * _LIBCPP_HAS_NO_TRAILING_RETURN * _LIBCPP_HAS_NO_TEMPLATE_ALIASES * _LIBCPP_HAS_NO_ADVANCED_SFINAE * _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS * _LIBCPP_HAS_NO_STATIC_ASSERT As a drive I also changed our C++03 static_assert to use _Static_assert if available. I plan to commit this without review if nobody voices an objection. Reviewers: mclow.lists Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D24895 Modified: libcxx/trunk/include/__config libcxx/trunk/include/iterator libcxx/trunk/include/memory libcxx/trunk/include/ratio libcxx/trunk/include/scoped_allocator libcxx/trunk/include/type_traits libcxx/trunk/test/std/containers/associative/map/map.cons/copy.pass.cpp libcxx/trunk/test/std/containers/associative/multimap/multimap.cons/copy.pass.cpp libcxx/trunk/test/std/containers/associative/multiset/multiset.cons/copy.pass.cpp libcxx/trunk/test/std/containers/associative/set/set.cons/copy.pass.cpp libcxx/trunk/test/std/containers/sequences/deque/deque.cons/copy.pass.cpp libcxx/trunk/test/std/containers/sequences/forwardlist/forwardlist.cons/copy.pass.cpp libcxx/trunk/test/std/containers/sequences/list/list.cons/copy.pass.cpp libcxx/trunk/test/std/containers/unord/unord.map/unord.map.cnstr/copy.pass.cpp libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/copy.pass.cpp libcxx/trunk/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy.pass.cpp libcxx/trunk/test/std/containers/unord/unord.set/unord.set.cnstr/copy.pass.cpp libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp libcxx/trunk/test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp libcxx/trunk/test/std/utilities/memory/pointer.traits/rebind.pass.cpp libcxx/trunk/test/support/test_allocator.h Modified: libcxx/trunk/include/__config URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=282347&r1=282346&r2=282347&view=diff == --- libcxx/trunk/include/__config (original) +++ libcxx/trunk/include/__config Sat Sep 24 22:34:28 2016 @@ -68,6 +68,9 @@ #define _LIBCPP_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION) +#if __cplusplus < 201103L +#define _LIBCPP_CXX03_LANG +#endif #ifndef __has_attribute #define __has_attribute(__x) 0 @@ -229,10 +232,6 @@ # define _ALIGNAS(x) __attribute__((__aligned__(x))) #endif -#if !__has_feature(cxx_alias_templates) -#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES -#endif - #if __cplusplus < 201103L typedef __char16_t char16_t; typedef __char32_t char32_t; @@ -260,10 +259,6 @@ typedef __char32_t char32_t; # define _LIBCPP_NORETURN __attribute__ ((noreturn)) #endif -#if !(__has_feature(cxx_default_function_template_args)) -#define _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS -#endif - #if !(__has_feature(cxx_defaulted_functions)) #define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS #endif // !(__has_feature(cxx_defaulted_functions)) @@ -284,26 +279,14 @@ typedef __char32_t char32_t; #define _LIBCPP_HAS_NO_RVALUE_REFERENCES #endif -#if !(__has_feature(cxx_static_assert)) -#define _LIBCPP_HAS_NO_STATIC_ASSERT -#endif - #if !(__has_feature(cxx_auto_type)) #define _LIBCPP_HAS_NO_AUTO_TYPE #endif -#if !(__has_feature(cxx_access_control_sfinae)) || !__has_feature(cxx_trailing_return) -#define _LIBCPP_HAS_NO_ADVANCED_SFINAE -#endif - #if !(__has_feature(cxx_variadic_templates)) #define _LIBCPP_HAS_NO_VARIADICS #endif -#if !(__has_feature(cxx_trailing_return)) -#define _LIBCPP_HAS_NO_TRAILING_RETURN -#endif - #if !(__has_feature(cxx_generalized_initializers)) #define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS #endif @@ -428,34 +411,26 @@ namespace std { #endif #ifndef __GXX_EXPERIMENTAL_CXX0X__ - -#define _LIBCPP_HAS_NO_ADVANCED_SFINAE #define _LIBCPP_HAS_NO_DECLTYPE -#define _LIBCPP_HAS_NO_DEFAULT_FUNCTION_
Re: [PATCH] D24895: [libc++] Remove various C++03 feature test macros
EricWF updated this revision to Diff 72411. EricWF added a comment. Fix merge conflicts. https://reviews.llvm.org/D24895 Files: include/__config include/iterator include/memory include/ratio include/scoped_allocator include/type_traits test/std/containers/associative/map/map.cons/copy.pass.cpp test/std/containers/associative/multimap/multimap.cons/copy.pass.cpp test/std/containers/associative/multiset/multiset.cons/copy.pass.cpp test/std/containers/associative/set/set.cons/copy.pass.cpp test/std/containers/sequences/deque/deque.cons/copy.pass.cpp test/std/containers/sequences/forwardlist/forwardlist.cons/copy.pass.cpp test/std/containers/sequences/list/list.cons/copy.pass.cpp test/std/containers/unord/unord.map/unord.map.cnstr/copy.pass.cpp test/std/containers/unord/unord.multimap/unord.multimap.cnstr/copy.pass.cpp test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy.pass.cpp test/std/containers/unord/unord.set/unord.set.cnstr/copy.pass.cpp test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp test/std/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp test/std/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp test/std/utilities/memory/pointer.traits/rebind.pass.cpp test/support/test_allocator.h Index: test/support/test_allocator.h === --- test/support/test_allocator.h +++ test/support/test_allocator.h @@ -66,7 +66,7 @@ { assert(data_ >= 0); if (time_to_throw >= throw_after) { -#ifndef _LIBCPP_NO_EXCEPTIONS +#ifndef TEST_HAS_NO_EXCEPTIONS throw std::bad_alloc(); #else std::terminate(); @@ -130,7 +130,7 @@ { assert(data_ >= 0); if (time_to_throw >= throw_after) { -#ifndef _LIBCPP_NO_EXCEPTIONS +#ifndef TEST_HAS_NO_EXCEPTIONS throw std::bad_alloc(); #else std::terminate(); @@ -221,10 +221,10 @@ typedef std::true_type propagate_on_container_move_assignment; typedef std::true_type propagate_on_container_swap; -#ifdef _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if TEST_STD_VER < 11 std::size_t max_size() const {return UINT_MAX / sizeof(T);} -#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#endif }; Index: test/std/utilities/memory/pointer.traits/rebind.pass.cpp === --- test/std/utilities/memory/pointer.traits/rebind.pass.cpp +++ test/std/utilities/memory/pointer.traits/rebind.pass.cpp @@ -19,9 +19,11 @@ #include #include +#include "test_macros.h" + int main() { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#if TEST_STD_VER >= 11 static_assert((std::is_same::rebind, double*>::value), ""); #else static_assert((std::is_same::rebind::other, double*>::value), ""); Index: test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp === --- test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp +++ test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp @@ -19,6 +19,8 @@ #include #include +#include "test_macros.h" + template struct ReboundA {}; @@ -63,17 +65,17 @@ int main() { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#if TEST_STD_VER >= 11 static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); -#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#else static_assert((std::is_same >::rebind_traits::other, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits::other, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits::other, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits::other, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits::other, std::allocator_traits > >::value), ""); -#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#endif } Index: test/std/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp === --- test/std/utilities/memory/allocator.trai
Re: [PATCH] D24895: [libc++] Remove various C++03 feature test macros
EricWF updated this revision to Diff 72410. EricWF added a comment. Actually remove _LIBCPP_HAS_NO_STATIC_ASSERT. https://reviews.llvm.org/D24895 Files: include/__config include/iterator include/memory include/ratio include/scoped_allocator include/type_traits src/string.cpp test/std/containers/associative/map/map.cons/copy.pass.cpp test/std/containers/associative/multimap/multimap.cons/copy.pass.cpp test/std/containers/associative/multiset/multiset.cons/copy.pass.cpp test/std/containers/associative/set/set.cons/copy.pass.cpp test/std/containers/sequences/deque/deque.cons/copy.pass.cpp test/std/containers/sequences/forwardlist/forwardlist.cons/copy.pass.cpp test/std/containers/sequences/list/list.cons/copy.pass.cpp test/std/containers/unord/unord.map/unord.map.cnstr/copy.pass.cpp test/std/containers/unord/unord.multimap/unord.multimap.cnstr/copy.pass.cpp test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy.pass.cpp test/std/containers/unord/unord.set/unord.set.cnstr/copy.pass.cpp test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp test/std/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp test/std/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp test/std/utilities/memory/pointer.traits/rebind.pass.cpp test/support/test_allocator.h Index: test/support/test_allocator.h === --- test/support/test_allocator.h +++ test/support/test_allocator.h @@ -66,7 +66,7 @@ { assert(data_ >= 0); if (time_to_throw >= throw_after) { -#ifndef _LIBCPP_NO_EXCEPTIONS +#ifndef TEST_HAS_NO_EXCEPTIONS throw std::bad_alloc(); #else std::terminate(); @@ -130,7 +130,7 @@ { assert(data_ >= 0); if (time_to_throw >= throw_after) { -#ifndef _LIBCPP_NO_EXCEPTIONS +#ifndef TEST_HAS_NO_EXCEPTIONS throw std::bad_alloc(); #else std::terminate(); @@ -221,10 +221,10 @@ typedef std::true_type propagate_on_container_move_assignment; typedef std::true_type propagate_on_container_swap; -#ifdef _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if TEST_STD_VER < 11 std::size_t max_size() const {return UINT_MAX / sizeof(T);} -#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#endif }; Index: test/std/utilities/memory/pointer.traits/rebind.pass.cpp === --- test/std/utilities/memory/pointer.traits/rebind.pass.cpp +++ test/std/utilities/memory/pointer.traits/rebind.pass.cpp @@ -19,9 +19,11 @@ #include #include +#include "test_macros.h" + int main() { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#if TEST_STD_VER >= 11 static_assert((std::is_same::rebind, double*>::value), ""); #else static_assert((std::is_same::rebind::other, double*>::value), ""); Index: test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp === --- test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp +++ test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp @@ -19,6 +19,8 @@ #include #include +#include "test_macros.h" + template struct ReboundA {}; @@ -63,17 +65,17 @@ int main() { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#if TEST_STD_VER >= 11 static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); -#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#else static_assert((std::is_same >::rebind_traits::other, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits::other, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits::other, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits::other, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits::other, std::alloca
[libcxx] r282345 - Use __attribute__((internal_linkage)) when available.
Author: ericwf Date: Sat Sep 24 22:14:13 2016 New Revision: 282345 URL: http://llvm.org/viewvc/llvm-project?rev=282345&view=rev Log: Use __attribute__((internal_linkage)) when available. Summary: This patch has been a long time coming (Thanks @eugenis). It changes `_LIBCPP_INLINE_VISIBILITY` to use `__attribute__((internal_linkage))` instead of `__attribute__((visibility("hidden"), always_inline))`. The point of `_LIBCPP_INLINE_VISIBILITY` is to prevent inline functions from being exported from both the libc++ library and from user libraries. This helps libc++ better manage it's ABI. Previously this was done by forcing inlining and modifying the symbols visibility. However inlining isn't guaranteed and symbol visibility only affects shared libraries making this an imperfect solution. `internal_linkage` improves this situation by making all symbols local to the TU they are emitted in, regardless of inlining or visibility. IIRC the effect of applying `__attribute__((internal_linkage))` to an inline function is the same as applying `static`. For more information about the attribute see: http://lists.llvm.org/pipermail/cfe-dev/2015-October/045580.html Most of the work for this patch was done by @eugenis. Reviewers: mclow.lists, eugenis Subscribers: eugenis, cfe-commits Differential Revision: https://reviews.llvm.org/D24642 Modified: libcxx/trunk/include/__config libcxx/trunk/src/string.cpp Modified: libcxx/trunk/include/__config URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=282345&r1=282344&r2=282345&view=diff == --- libcxx/trunk/include/__config (original) +++ libcxx/trunk/include/__config Sat Sep 24 22:14:13 2016 @@ -34,6 +34,7 @@ #endif #if defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2 +#define _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION 2 // Change short string representation so that string data starts at offset 0, // improving its alignment in some cases. #define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT @@ -49,6 +50,7 @@ #define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE #define _LIBCPP_ABI_VARIADIC_LOCK_GUARD #elif _LIBCPP_ABI_VERSION == 1 +#define _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION 1 // Feature macros for disabling pre ABI v1 features. All of these options // are deprecated. #if defined(__FreeBSD__) @@ -629,11 +631,19 @@ namespace std { #endif #ifndef _LIBCPP_INLINE_VISIBILITY -#define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), __always_inline__)) +# if __has_attribute(__internal_linkage__) +# define _LIBCPP_INLINE_VISIBILITY __attribute__((__internal_linkage__, __always_inline__)) +# else +# define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), __always_inline__)) +# endif #endif #ifndef _LIBCPP_ALWAYS_INLINE -#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__visibility__("hidden"), __always_inline__)) +# if __has_attribute(__internal_linkage__) +# define _LIBCPP_ALWAYS_INLINE __attribute__((__internal_linkage__, __always_inline__)) +# else +# define _LIBCPP_ALWAYS_INLINE __attribute__ ((__visibility__("hidden"), __always_inline__)) +# endif #endif #ifndef _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY Modified: libcxx/trunk/src/string.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/string.cpp?rev=282345&r1=282344&r2=282345&view=diff == --- libcxx/trunk/src/string.cpp (original) +++ libcxx/trunk/src/string.cpp Sat Sep 24 22:14:13 2016 @@ -29,6 +29,29 @@ template string operator+, allocator >(char const*, string const&); +// These external instantiations are required to maintain dylib compatibility +// for ABI v1 when using __attribute__((internal_linkage)) as opposed to +// __attribute__((visibility("hidden"), always_inline)). +#if _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION == 1 +template basic_string::iterator +basic_string::insert(basic_string::const_iterator, + char const *, char const *); + +template basic_string::iterator +basic_string::insert(basic_string::const_iterator, + wchar_t const *, wchar_t const *); + +template basic_string & +basic_string::replace(basic_string::const_iterator, + basic_string::const_iterator, + char const *, char const *); + +template basic_string & +basic_string::replace(basic_string::const_iterator, + basic_string::const_iterator, + wchar_t const *, wchar_t const *); +#endif // _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION + namespace { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24893: [clang-tidy] make readability-redundant-smartptr-get report get() usage in conditions
alexfh added inline comments. Comment at: clang-tidy/readability/RedundantSmartptrGetCheck.cpp:64 @@ -63,3 +63,3 @@ const auto IsAKnownSmartptr = recordDecl( anyOf(hasName("::std::unique_ptr"), hasName("::std::shared_ptr"))); BTW, this can be done using hasAnyName. https://reviews.llvm.org/D24893 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24893: [clang-tidy] make readability-redundant-smartptr-get report get() usage in conditions
alexfh accepted this revision. alexfh added a comment. This revision is now accepted and ready to land. LG. Thank you! https://reviews.llvm.org/D24893 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libcxx] r282343 - Fix a few static_asserts that need extra parens on -03
Author: marshall Date: Sat Sep 24 18:52:21 2016 New Revision: 282343 URL: http://llvm.org/viewvc/llvm-project?rev=282343&view=rev Log: Fix a few static_asserts that need extra parens on -03 Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp?rev=282343&r1=282342&r2=282343&view=diff == --- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp (original) +++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_insert/size_T_size_size.pass.cpp Sat Sep 24 18:52:21 2016 @@ -27,7 +27,7 @@ void test(S s, typename S::size_type pos1, SV sv, typename S::size_type pos2, typename S::size_type n, S expected) { -static_assert(!std::is_same::value, ""); +static_assert((!std::is_same::value), ""); typename S::size_type old_size = s.size(); S s0 = s; try @@ -48,7 +48,7 @@ template void test_npos(S s, typename S::size_type pos1, SV sv, typename S::size_type pos2, S expected) { -static_assert(!std::is_same::value, ""); +static_assert((!std::is_same::value), ""); typename S::size_type old_size = s.size(); S s0 = s; try Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp?rev=282343&r1=282342&r2=282343&view=diff == --- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp (original) +++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_replace/size_size_T_size_size.pass.cpp Sat Sep 24 18:52:21 2016 @@ -30,7 +30,7 @@ test(S s, typename S::size_type pos1, ty SV sv, typename S::size_type pos2, typename S::size_type n2, S expected) { -static_assert(!std::is_same::value, ""); +static_assert((!std::is_same::value), ""); typename S::size_type old_size = s.size(); S s0 = s; try @@ -56,7 +56,7 @@ test_npos(S s, typename S::size_type pos SV sv, typename S::size_type pos2, S expected) { -static_assert(!std::is_same::value, ""); +static_assert((!std::is_same::value), ""); typename S::size_type old_size = s.size(); S s0 = s; try Modified: libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp?rev=282343&r1=282342&r2=282343&view=diff == --- libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp (original) +++ libcxx/trunk/test/std/strings/basic.string/string.ops/string_compare/size_size_T_size_size.pass.cpp Sat Sep 24 18:52:21 2016 @@ -36,7 +36,7 @@ void test(const S& s, typename S::size_type pos1, typename S::size_type n1, SV sv, typename S::size_type pos2, typename S::size_type n2, int x) { -static_assert(!std::is_same::value, ""); +static_assert((!std::is_same::value), ""); try { assert(sign(s.compare(pos1, n1, sv, pos2, n2)) == sign(x)); @@ -54,7 +54,7 @@ void test_npos(const S& s, typename S::size_type pos1, typename S::size_type n1, SV sv, typename S::size_type pos2, int x) { -static_assert(!std::is_same::value, ""); +static_assert((!std::is_same::value), ""); try { assert(sign(s.compare(pos1, n1, sv, pos2)) == sign(x)); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D24895: [libc++] Remove various C++03 feature test macros
EricWF created this revision. EricWF added a reviewer: mclow.lists. EricWF added a subscriber: cfe-commits. Libc++ still uses per-feature configuration macros when configuring for C++11. However libc++ requires a feature-complete C++11 compiler so there is no reason to check individual features. This patch starts the process of removing the feature specific macros and replacing their usage with `_LIBCPP_CXX03_LANG`. This patch removes the __config macros: * _LIBCPP_HAS_NO_TRAILING_RETURN * _LIBCPP_HAS_NO_TEMPLATE_ALIASES * _LIBCPP_HAS_NO_ADVANCED_SFINAE * _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS * _LIBCPP_HAS_NO_STATIC_ASSERT As a drive I also changed our C++03 static_assert to use _Static_assert if available. I plan to commit this without review if nobody voices an objection. https://reviews.llvm.org/D24895 Files: include/__config include/iterator include/memory include/ratio include/scoped_allocator include/type_traits test/std/containers/associative/map/map.cons/copy.pass.cpp test/std/containers/associative/multimap/multimap.cons/copy.pass.cpp test/std/containers/associative/multiset/multiset.cons/copy.pass.cpp test/std/containers/associative/set/set.cons/copy.pass.cpp test/std/containers/sequences/deque/deque.cons/copy.pass.cpp test/std/containers/sequences/forwardlist/forwardlist.cons/copy.pass.cpp test/std/containers/sequences/list/list.cons/copy.pass.cpp test/std/containers/unord/unord.map/unord.map.cnstr/copy.pass.cpp test/std/containers/unord/unord.multimap/unord.multimap.cnstr/copy.pass.cpp test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy.pass.cpp test/std/containers/unord/unord.set/unord.set.cnstr/copy.pass.cpp test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp test/std/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp test/std/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp test/std/utilities/memory/pointer.traits/rebind.pass.cpp test/support/test_allocator.h Index: test/support/test_allocator.h === --- test/support/test_allocator.h +++ test/support/test_allocator.h @@ -66,7 +66,7 @@ { assert(data_ >= 0); if (time_to_throw >= throw_after) { -#ifndef _LIBCPP_NO_EXCEPTIONS +#ifndef TEST_HAS_NO_EXCEPTIONS throw std::bad_alloc(); #else std::terminate(); @@ -130,7 +130,7 @@ { assert(data_ >= 0); if (time_to_throw >= throw_after) { -#ifndef _LIBCPP_NO_EXCEPTIONS +#ifndef TEST_HAS_NO_EXCEPTIONS throw std::bad_alloc(); #else std::terminate(); @@ -221,10 +221,10 @@ typedef std::true_type propagate_on_container_move_assignment; typedef std::true_type propagate_on_container_swap; -#ifdef _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if TEST_STD_VER < 11 std::size_t max_size() const {return UINT_MAX / sizeof(T);} -#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#endif }; Index: test/std/utilities/memory/pointer.traits/rebind.pass.cpp === --- test/std/utilities/memory/pointer.traits/rebind.pass.cpp +++ test/std/utilities/memory/pointer.traits/rebind.pass.cpp @@ -19,9 +19,11 @@ #include #include +#include "test_macros.h" + int main() { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#if TEST_STD_VER >= 11 static_assert((std::is_same::rebind, double*>::value), ""); #else static_assert((std::is_same::rebind::other, double*>::value), ""); Index: test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp === --- test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp +++ test/std/utilities/memory/allocator.traits/rebind_traits.pass.cpp @@ -19,6 +19,8 @@ #include #include +#include "test_macros.h" + template struct ReboundA {}; @@ -63,17 +65,17 @@ int main() { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#if TEST_STD_VER >= 11 static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); static_assert((std::is_same >::rebind_traits, std::allocator_traits > >::value), ""); -#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#else static_assert((std::is_same >::rebind_traits::other, std::alloc
[PATCH] D24894: [clang-tidy] Prefer transparent functors to non-transparent one.
xazax.hun created this revision. xazax.hun added reviewers: alexfh, hokein. xazax.hun added a subscriber: cfe-commits. xazax.hun set the repository for this revision to rL LLVM. xazax.hun added a project: clang-tools-extra. Herald added subscribers: mgorny, beanz. This check finds the usages of non-transparent functors and suggest to use the transparent ones. This check seems to be surprisingly slow though. Maybe because the amount of typelocs in the source code? I did not have a chance to do a profiling yet, but plan to do it later. Feel free to postpone the review until the profiling is done. Repository: rL LLVM https://reviews.llvm.org/D24894 Files: clang-tidy/modernize/CMakeLists.txt clang-tidy/modernize/ModernizeTidyModule.cpp clang-tidy/modernize/UseTransparentFunctorsCheck.cpp clang-tidy/modernize/UseTransparentFunctorsCheck.h docs/ReleaseNotes.rst docs/clang-tidy/checks/list.rst docs/clang-tidy/checks/modernize-use-transparent-functors.rst test/clang-tidy/modernize-use-transparent-functors.cpp Index: test/clang-tidy/modernize-use-transparent-functors.cpp === --- /dev/null +++ test/clang-tidy/modernize-use-transparent-functors.cpp @@ -0,0 +1,100 @@ +// RUN: %check_clang_tidy %s modernize-use-transparent-functors %t -- -- -std=c++14 + +namespace std { +template +struct remove_reference; + +template +constexpr T &&forward(typename std::remove_reference::type &t); + +template +constexpr T &&forward(typename std::remove_reference::type &&t); + +template +struct plus { + constexpr T operator()(const T &Lhs, const T &Rhs) const; +}; + +template <> +struct plus { + template + constexpr auto operator()(T &&Lhs, U &&Rhs) const -> +decltype(forward(Lhs) + forward(Rhs)); +}; + +template +struct less { + constexpr bool operator()(const T &Lhs, const T &Rhs) const; +}; + +template <> +struct less { + template + constexpr bool operator()(T &&Lhs, U &&Rhs) const; +}; + +template +struct logical_not { + constexpr bool operator()(const T &Arg) const; +}; + +template <> +struct logical_not { + template + constexpr bool operator()(T &&Arg) const; +}; + +template +class allocator; + +template < +class Key, +class Compare = std::less<>, +class Allocator = std::allocator> +class set {}; + +template +InputIt find_if(InputIt first, InputIt last, +UnaryPredicate p); + +template +void sort(RandomIt first, RandomIt last, Compare comp); + +class iterator {}; +class string {}; +} + +int main() { + using std::set; + using std::less; + std::set> s; + // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: prefer transparent functors [modernize-use-transparent-functors] + // CHECK-FIXES: {{^}} std::set> s;{{$}} + set> s2; + // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: prefer transparent functors + // CHECK-FIXES: {{^}} set> s2;{{$}} + set> s3; + // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: prefer transparent functors + // CHECK-FIXES: {{^}} set> s3;{{$}} + std::set> s4; + std::set> s5; + std::set>, std::less<>> s6; + // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: prefer transparent functors + // CHECK-FIXES: {{^}} std::set>, std::less<>> s6;{{$}} + std::iterator begin, end; + sort(begin, end, std::less()); + // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: prefer transparent functors + std::sort(begin, end, std::less<>()); + find_if(begin, end, std::logical_not()); + // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: prefer transparent functors + std::find_if(begin, end, std::logical_not<>()); + using my_set = std::set>; + // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: prefer transparent functors + // CHECK-FIXES: {{^}} using my_set = std::set>;{{$}} + using my_set2 = std::set>; + using my_less = std::less; + find_if(begin, end, my_less()); + // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: prefer transparent functors +} + + Index: docs/clang-tidy/checks/modernize-use-transparent-functors.rst === --- /dev/null +++ docs/clang-tidy/checks/modernize-use-transparent-functors.rst @@ -0,0 +1,24 @@ +.. title:: clang-tidy - modernize-use-transparent-functors + +modernize-use-transparent-functors +== + +Prefer transparent functors to non-transparent ones. Using transparent functors +the type does not need to be repeated. The code is easier to read, maintain and +less prone to errors. It not possible to introduce unwanted conversions. + + .. code-block:: c++ + +// Non-transparent functor +std::map> s; + +// Transparent functor. +std::map> s; + +It is not always a safe transformation though. The following case will be +untouched to preserve the semantics. + + .. code-block:: c++ + +// Non-transparent functor +std::map> s; Index: docs/clang-tidy/checks/list.rst === --- docs/clang-tidy/checks/list.rst +++ do
Re: [PATCH] D24446: Implement revision to LWG#2758
mclow.lists closed this revision. mclow.lists added a comment. Landed as revision 282342. Comment at: include/string:613 @@ +612,3 @@ + ( is_convertible >::value && + !is_convertible::value)) {}; + EricWF wrote: > The discussion for LWG 2758 gives a `replace` test case for this condition. > Could you add that test to our suite? I think I have an equivalent test - passing a non-const char * . That should be about line 5994 of string_replace/size_size_T_size_size.pass.cpp https://reviews.llvm.org/D24446 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D24893: [clang-tidy] make readability-redundant-smartptr-get report get() usage in conditions
omtcyfz created this revision. omtcyfz added reviewers: alexfh, klimek, ioeric. omtcyfz added subscribers: cfe-commits, Eugene.Zelenko. This patch extends clang-tidy's readability-redundant-smartptr-get to produce warnings for previously unsupported cases: ``` std::unique_ptr ptr; if (ptr.get()) if (ptr.get() == NULL) if (ptr.get() != NULL) ``` This is intended to fix https://llvm.org/bugs/show_bug.cgi?id=25804, a bug report opened by @eugene.zelenko. However, there still are cases not detected by the check. They can be found in `void Negative()` function defined in test/clang-tidy/readability-redundant-smartptr-get.cpp. https://reviews.llvm.org/D24893 Files: clang-tidy/readability/RedundantSmartptrGetCheck.cpp test/clang-tidy/readability-redundant-smartptr-get.cpp Index: test/clang-tidy/readability-redundant-smartptr-get.cpp === --- test/clang-tidy/readability-redundant-smartptr-get.cpp +++ test/clang-tidy/readability-redundant-smartptr-get.cpp @@ -113,6 +113,37 @@ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call // CHECK-MESSAGES: i = *PointerWithOverloadedGet().get(); // CHECK-FIXES: i = *PointerWithOverloadedGet(); + + bb = std::unique_ptr().get() == NULL; + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call + // CHECK-MESSAGES: bb = std::unique_ptr().get() == NULL; + // CHECK-FIXES: bb = std::unique_ptr() == NULL; + bb = ss->get() == NULL; + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call + // CHECK-MESSAGES: bb = ss->get() == NULL; + // CHECK-FIXES: bb = *ss == NULL; + + std::unique_ptr x, y; + if (x.get() == nullptr); + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call + // CHECK-MESSAGES: if (x.get() == nullptr); + // CHECK-FIXES: if (x == nullptr); + if (nullptr == y.get()); + // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: redundant get() call + // CHECK-MESSAGES: if (nullptr == y.get()); + // CHECK-FIXES: if (nullptr == y); + if (x.get() == NULL); + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call + // CHECK-MESSAGES: if (x.get() == NULL); + // CHECK-FIXES: if (x == NULL); + if (NULL == x.get()); + // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: redundant get() call + // CHECK-MESSAGES: if (NULL == x.get()); + // CHECK-FIXES: if (NULL == x); + if (x.get()); + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call + // CHECK-MESSAGES: if (x.get()); + // CHECK-FIXES: if (x); } void Negative() { @@ -137,7 +168,5 @@ (*Fail2().get()).Do(); int_ptr ip; - bool bb = std::unique_ptr().get() == NULL; - bb = ip.get() == nullptr; - bb = u->get() == NULL; + bool bb = ip.get() == nullptr; } Index: clang-tidy/readability/RedundantSmartptrGetCheck.cpp === --- clang-tidy/readability/RedundantSmartptrGetCheck.cpp +++ clang-tidy/readability/RedundantSmartptrGetCheck.cpp @@ -65,16 +65,22 @@ // Matches against nullptr. Finder->addMatcher( - binaryOperator( - anyOf(hasOperatorName("=="), hasOperatorName("!=")), - hasEitherOperand(ignoringImpCasts(cxxNullPtrLiteralExpr())), - hasEitherOperand(callToGet(IsAKnownSmartptr))), + binaryOperator(anyOf(hasOperatorName("=="), hasOperatorName("!=")), + hasEitherOperand(ignoringImpCasts( + anyOf(cxxNullPtrLiteralExpr(), gnuNullExpr(), + integerLiteral(equals(0), + hasEitherOperand(callToGet(IsAKnownSmartptr))), + Callback); + + // Matches against if(ptr.get()) + Finder->addMatcher( + ifStmt(hasCondition(ignoringImpCasts(callToGet(IsAKnownSmartptr, Callback); - // TODO: Catch ptr.get() == other_ptr.get() -} + // FIXME: Match and fix if (l.get() == r.get()). +} -} // namespace +} // namespace void RedundantSmartptrGetCheck::registerMatchers(MatchFinder *Finder) { // Only register the matchers for C++; the functionality currently does not @@ -102,10 +108,11 @@ Result.Nodes.getNodeAs("getType")->getUnqualifiedDesugaredType(); return OpArrowType == OpStarType && OpArrowType == GetType; } -} // namespace +} // namespace void RedundantSmartptrGetCheck::check(const MatchFinder::MatchResult &Result) { - if (!allReturnTypesMatch(Result)) return; + if (!allReturnTypesMatch(Result)) +return; bool IsPtrToPtr = Result.Nodes.getNodeAs("ptr_to_ptr") != nullptr; bool IsMemberExpr = Result.Nodes.getNodeAs("memberExpr") != nullptr; Index: test/clang-tidy/readability-redundant-smartptr-get.cpp === --- test/clang-tidy/readability-redundant-smartptr-get.cpp +++ test/clang-tidy/readability-redundant-smartptr-get.cpp @@ -113,6 +113,37 @@ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call // CHECK-MESSAGES: i = *PointerWithOverloadedGet().
Re: [PATCH] D24791: Use checktime when reloading vim buffer after applying clang-rename
omtcyfz added a comment. @NewProggie do you have commit access or do you want me to land this patch for you? https://reviews.llvm.org/D24791 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24791: Use checktime when reloading vim buffer after applying clang-rename
omtcyfz accepted this revision. omtcyfz added a comment. This revision is now accepted and ready to land. Sorry for a late response. Yes, this solution is way better. Honestly I just didn't know how to achieve that; not a Vim pro here :) Thank you very much! LGTM. https://reviews.llvm.org/D24791 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24892: [clang-tidy] Add option "LiteralInitializers" to cppcoreguidelines-pro-type-member-init
mgehre updated this revision to Diff 72394. mgehre added a comment. Extend test to negative case https://reviews.llvm.org/D24892 Files: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst test/clang-tidy/cppcoreguidelines-pro-type-member-init-literal-initializers.cpp Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init-literal-initializers.cpp === --- /dev/null +++ test/clang-tidy/cppcoreguidelines-pro-type-member-init-literal-initializers.cpp @@ -0,0 +1,21 @@ +// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-member-init %t -- -config="{CheckOptions: [{key: "cppcoreguidelines-pro-type-member-init.LiteralInitializers", value: 1}]}" -- -std=c++11 + +struct T { + int i; +}; + +struct S { + bool b; + // CHECK-FIXES: bool b = false; + int i; + // CHECK-FIXES: int i = 0; + float f; + // CHECK-FIXES: float f = 0.0; + int* ptr; + // CHECK-FIXES: int* ptr = nullptr; + T t; + // CHECK-FIXES: T t{}; + S() {}; + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: +}; + Index: docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst === --- docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst +++ docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst @@ -33,6 +33,10 @@ zero-initialized during construction. For performance critical code, it may be important to not initialize fixed-size array members. Default is `0`. +.. option:: LiteralInitializers + If set to non-zero, the check will provide fix-its with literal initializers + (``int i = 0;``) instead of curly braces (``int i{};``). + This rule is part of the "Type safety" profile of the C++ Core Guidelines, corresponding to rule Type.6. See https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-type-memberinit. Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h === --- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h +++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h @@ -63,6 +63,9 @@ // Whether arrays need to be initialized or not. Default is false. bool IgnoreArrays; + // Whether fix-its for initializers of fundamental type use literals. Only + // effective in C++11 mode. Default is false. + bool LiteralInitializers; }; } // namespace cppcoreguidelines Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp === --- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp +++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp @@ -251,7 +251,8 @@ ProTypeMemberInitCheck::ProTypeMemberInitCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), - IgnoreArrays(Options.get("IgnoreArrays", false)) {} + IgnoreArrays(Options.get("IgnoreArrays", false)), + LiteralInitializers(Options.get("LiteralInitializers", false)) {} void ProTypeMemberInitCheck::registerMatchers(MatchFinder *Finder) { if (!getLangOpts().CPlusPlus) @@ -296,6 +297,7 @@ void ProTypeMemberInitCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "IgnoreArrays", IgnoreArrays); + Options.store(Opts, "LiteralInitializers", LiteralInitializers); } void ProTypeMemberInitCheck::checkMissingMemberInitializer( @@ -366,9 +368,21 @@ // Use in-class initialization if possible. if (Context.getLangOpts().CPlusPlus11) { for (const FieldDecl *Field : FieldsToFix) { + QualType type = Field->getType(); + const char *Initializer = "{}"; + if (LiteralInitializers) { +if (type->isBooleanType()) + Initializer = " = false"; +else if (type->isIntegerType()) + Initializer = " = 0"; +else if (type->isFloatingType()) + Initializer = " = 0.0"; +else if (type->isPointerType()) + Initializer = " = nullptr"; + } Diag << FixItHint::CreateInsertion( getLocationForEndOfToken(Context, Field->getSourceRange().getEnd()), - "{}"); + Initializer); } } else { // Otherwise, rewrite the constructor's initializer list. Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init-literal-initializers.cpp === --- /dev/null +++ test/clang-tidy/cppcoreguidelines-pro-type-member-init-literal-initializers.cpp @@ -0,0 +1,21 @@ +// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-member-init %t -- -config="{CheckOptions: [{key: "cppcoreguidelines-pro-type-member-init.LiteralInitializers", value: 1}]}" -- -std=c++11 + +struct T { +
[PATCH] D24892: [clang-tidy] Add option "LiteralInitializers" to cppcoreguidelines-pro-type-member-init
mgehre created this revision. mgehre added reviewers: alexfh, aaron.ballman, hokein. mgehre added a subscriber: cfe-commits. Herald added a subscriber: nemanjai. Adds the option "LiteralInitializers" to cppcoreguidelines-pro-type-member-init. If set to non-zero, the check will provide fix-its with literal initializers (``int i = 0;``) instead of curly braces (``int i{};``). If find that more readable. Of course, this is purely a question of style, thus the option is disabled by default. https://reviews.llvm.org/D24892 Files: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst test/clang-tidy/cppcoreguidelines-pro-type-member-init-literal-initializers.cpp Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init-literal-initializers.cpp === --- /dev/null +++ test/clang-tidy/cppcoreguidelines-pro-type-member-init-literal-initializers.cpp @@ -0,0 +1,15 @@ +// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-member-init %t -- -config="{CheckOptions: [{key: "cppcoreguidelines-pro-type-member-init.LiteralInitializers", value: 1}]}" -- -std=c++11 + +struct S { + bool b; + // CHECK-FIXES: bool b = false; + int i; + // CHECK-FIXES: int i = 0; + float f; + // CHECK-FIXES: float f = 0.0; + int* ptr; + // CHECK-FIXES: int* ptr = nullptr; + S() {}; + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: +}; + Index: docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst === --- docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst +++ docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst @@ -33,6 +33,10 @@ zero-initialized during construction. For performance critical code, it may be important to not initialize fixed-size array members. Default is `0`. +.. option:: LiteralInitializers + If set to non-zero, the check will provide fix-its with literal initializers + (``int i = 0;``) instead of curly braces (``int i{};``). + This rule is part of the "Type safety" profile of the C++ Core Guidelines, corresponding to rule Type.6. See https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-type-memberinit. Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h === --- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h +++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h @@ -63,6 +63,9 @@ // Whether arrays need to be initialized or not. Default is false. bool IgnoreArrays; + // Whether fix-its for initializers of fundamental type use literals. Only + // effective in C++11 mode. Default is false. + bool LiteralInitializers; }; } // namespace cppcoreguidelines Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp === --- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp +++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp @@ -251,7 +251,8 @@ ProTypeMemberInitCheck::ProTypeMemberInitCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), - IgnoreArrays(Options.get("IgnoreArrays", false)) {} + IgnoreArrays(Options.get("IgnoreArrays", false)), + LiteralInitializers(Options.get("LiteralInitializers", false)) {} void ProTypeMemberInitCheck::registerMatchers(MatchFinder *Finder) { if (!getLangOpts().CPlusPlus) @@ -296,6 +297,7 @@ void ProTypeMemberInitCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "IgnoreArrays", IgnoreArrays); + Options.store(Opts, "LiteralInitializers", LiteralInitializers); } void ProTypeMemberInitCheck::checkMissingMemberInitializer( @@ -366,9 +368,21 @@ // Use in-class initialization if possible. if (Context.getLangOpts().CPlusPlus11) { for (const FieldDecl *Field : FieldsToFix) { + QualType type = Field->getType(); + const char *Initializer = "{}"; + if (LiteralInitializers) { +if (type->isBooleanType()) + Initializer = " = false"; +else if (type->isIntegerType()) + Initializer = " = 0"; +else if (type->isFloatingType()) + Initializer = " = 0.0"; +else if (type->isPointerType()) + Initializer = " = nullptr"; + } Diag << FixItHint::CreateInsertion( getLocationForEndOfToken(Context, Field->getSourceRange().getEnd()), - "{}"); + Initializer); } } else { // Otherwise, rewrite the constructor's initializer list. Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init-literal-initializers.cpp
Re: [PATCH] D22587: [ASTContext] Fix part of DR224 for nontype template arguments
mgehre added a comment. I'm sorry if this sounds dumb, but is there a way for me to follow that particular discussion? https://reviews.llvm.org/D22587 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D22968: [analyzer] A checker for macOS-specific bool- and number-like objects.
NoQ retitled this revision from "[analyzer] A checker for macOS-specific bool-like objects." to "[analyzer] A checker for macOS-specific bool- and number-like objects.". NoQ updated the summary for this revision. NoQ updated this revision to Diff 72392. NoQ marked 10 inline comments as done. NoQ added a comment. Herald added subscribers: mgorny, beanz. The checker now checks conversions of `NSNumber` to integer types, not just boolean. To do now - a bit more time needed to test various tweaks. The current version of the non-pedantic checker has found a couple of good new true positives, being relatively silent in general. I'm keeping positives of form `x == 0` (where `x` is a number pointer) in non-pedantic checker, even though they have been reporting non-bugs, because bugs of this form have been found, and it seems very desirable to make the code more specific in this particular case. To do later - consider conversions by passing NSNumber to a function that expects an integer, consider OSNumber and maybe CFNumber(?). https://reviews.llvm.org/D22968 Files: include/clang/StaticAnalyzer/Checkers/Checkers.td lib/StaticAnalyzer/Checkers/CMakeLists.txt lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp test/Analysis/Inputs/system-header-simulator-objc.h test/Analysis/NSNumber-conversion.m test/Analysis/OSBoolean-conversion.cpp Index: test/Analysis/OSBoolean-conversion.cpp === --- /dev/null +++ test/Analysis/OSBoolean-conversion.cpp @@ -0,0 +1,49 @@ +// RUN: %clang_cc1 -w -std=c++11 -analyze -analyzer-checker=osx.NumberObjectConversion %s -verify +// RUN: %clang_cc1 -w -std=c++11 -analyze -analyzer-checker=osx.NumberObjectConversion -analyzer-config osx.NumberObjectConversion:Pedantic=true -DPEDANTIC %s -verify + +#define NULL ((void *)0) +#include "Inputs/system-header-simulator-cxx.h" // for nullptr + +class OSBoolean { +public: + virtual bool isTrue() const; + virtual bool isFalse() const; +}; + +extern const OSBoolean *const &kOSBooleanFalse; +extern const OSBoolean *const &kOSBooleanTrue; + +void bad(const OSBoolean *p) { +#ifdef PEDANTIC + if (p) {} // expected-warning{{Converting 'const class OSBoolean *' to a plain boolean value for branching; please compare the pointer to NULL or nullptr instead to suppress this warning}} + if (!p) {} // expected-warning{{Converting 'const class OSBoolean *' to a plain boolean value for branching; please compare the pointer to NULL or nullptr instead to suppress this warning}} + p ? 1 : 2; // expected-warning{{Converting 'const class OSBoolean *' to a plain boolean value for branching; please compare the pointer to NULL or nullptr instead to suppress this warning}} + (bool)p; // expected-warning{{Converting 'const class OSBoolean *' to a plain bool value; please compare the pointer to NULL or nullptr instead to suppress this warning}} +#endif + bool x = p; // expected-warning{{Converting 'const class OSBoolean *' to a plain bool value; pointer value is being used instead}} + x = p; // expected-warning{{Converting 'const class OSBoolean *' to a plain bool value; pointer value is being used instead}} +} + +typedef bool sugared_bool; +typedef const OSBoolean *sugared_OSBoolean; +void bad_sugared(sugared_OSBoolean p) { + sugared_bool x = p; // expected-warning{{Converting 'const class OSBoolean *' to a plain bool value; pointer value is being used instead}} +} + +void good(const OSBoolean *p) { + bool x = p->isTrue(); // no-warning + (bool)p->isFalse(); // no-warning + if (p == kOSBooleanTrue) {} // no-warning +} + +void suppression(const OSBoolean *p) { + if (p == NULL) {} // no-warning + bool y = (p == nullptr); // no-warning +} + +// Test a different definition of NULL. +#undef NULL +#define NULL 0 +void test_non_pointer_NULL(const OSBoolean *p) { + if (p == NULL) {} // no-warning +} Index: test/Analysis/NSNumber-conversion.m === --- /dev/null +++ test/Analysis/NSNumber-conversion.m @@ -0,0 +1,67 @@ +// RUN: %clang_cc1 -fblocks -w -analyze -analyzer-checker=osx.NumberObjectConversion %s -verify +// RUN: %clang_cc1 -fblocks -w -analyze -analyzer-checker=osx.NumberObjectConversion -analyzer-config osx.NumberObjectConversion:Pedantic=true -DPEDANTIC %s -verify +// RUN: %clang_cc1 -fblocks -fobjc-arc -w -analyze -analyzer-checker=osx.NumberObjectConversion %s -verify +// RUN: %clang_cc1 -fblocks -fobjc-arc -w -analyze -analyzer-checker=osx.NumberObjectConversion -analyzer-config osx.NumberObjectConversion:Pedantic=true -DPEDANTIC %s -verify + +#include "Inputs/system-header-simulator-objc.h" + +void bad(NSNumber *p) { +#ifdef PEDANTIC + if (p) {} // expected-warning{{Converting 'NSNumber *' to a plain boolean value for branching; please compare the pointer to nil instead to suppress this warning}} + if (!p) {} // expected-warning{{Converting 'NSNumber *' to a plain boolean value for branching;
[libcxx] r282332 - Fix incorrect include in is_error_code_enum.pass.cpp
Author: marshall Date: Sat Sep 24 13:16:53 2016 New Revision: 282332 URL: http://llvm.org/viewvc/llvm-project?rev=282332&view=rev Log: Fix incorrect include in is_error_code_enum.pass.cpp Modified: libcxx/trunk/test/std/diagnostics/syserr/is_error_code_enum.pass.cpp Modified: libcxx/trunk/test/std/diagnostics/syserr/is_error_code_enum.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/diagnostics/syserr/is_error_code_enum.pass.cpp?rev=282332&r1=282331&r2=282332&view=diff == --- libcxx/trunk/test/std/diagnostics/syserr/is_error_code_enum.pass.cpp (original) +++ libcxx/trunk/test/std/diagnostics/syserr/is_error_code_enum.pass.cpp Sat Sep 24 13:16:53 2016 @@ -9,11 +9,11 @@ // // UNSUPPORTED: c++03 -// +// // template <> struct is_error_code_enum<> : public false_type {}; -#include +#include #include #include "test_macros.h" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r281277 - [Sema] Fix PR30346: relax __builtin_object_size checks.
- Original Message - > From: "George Burgess IV" > To: "Hal Finkel" > Cc: "Richard Smith" , "Joerg Sonnenberger" > , "cfe-commits" > > Sent: Monday, September 19, 2016 11:21:33 PM > Subject: Re: r281277 - [Sema] Fix PR30346: relax __builtin_object_size checks. > > > WFM; I'll put together a patch that only allows this under > -fno-strict-aliasing. > > > I'm entirely unfamiliar with struct-path-tbaa, so Hal, do you see a > reason why struct-path-tbaa wouldn't play nicely with flexible > arrays at the end of types? Glancing at it, I don't think it should > cause problems, but a more authoritative answer would really be > appreciated. :) If it might cause issues now or in the future, I'm > happy to be conservative here if -fno-strict-path-tbaa is given, > too. We currently don't emit struct-path-tbaa for array members. We likely should, and we'll need to keep flexible array members in mind when we implement that extension. I don't think that the current representation has a way to represent an unbounded size (except for using ((size_t) -1), which might be as good as anything else). -Hal > > On Tue, Sep 13, 2016 at 2:00 PM, Joerg Sonnenberger via cfe-commits < > cfe-commits@lists.llvm.org > wrote: > > > On Tue, Sep 13, 2016 at 12:51:52PM -0700, Richard Smith wrote: > > On Tue, Sep 13, 2016 at 10:44 AM, Joerg Sonnenberger via > > cfe-commits < > > cfe-commits@lists.llvm.org > wrote: > > > > > IMO this should be restricted to code that explicitly disables > > > C/C++ > > > aliasing rules. > > > > > > Do you mean -fno-strict-aliasing or -fno-struct-path-tbaa or > > something else > > here? (I think we're not doing anyone any favours by making > > _FORTIFY_SOURCE > > say that a pattern is OK in cases when LLVM will in fact optimize > > on the > > assumption that it's UB, but I don't recall how aggressive > > -fstruct-path-tbaa is for trailing array members.) > > The former immediately, the latter potentially as well. I can't think > of > many use cases for this kind of idiom that don't involve type > prunning > and socket code is notoriously bad in that regard by necessity. > > > > Joerg > ___ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits > > -- Hal Finkel Lead, Compiler Technology and Programming Languages Leadership Computing Facility Argonne National Laboratory ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libcxx] r282331 - Implement is_error_code_v and is_error_condition_v for c++17. Rework the tests for is_error_code and is_error_condition, since they were really lacking. Thanks to Alisdair for the h
Author: marshall Date: Sat Sep 24 12:36:14 2016 New Revision: 282331 URL: http://llvm.org/viewvc/llvm-project?rev=282331&view=rev Log: Implement is_error_code_v and is_error_condition_v for c++17. Rework the tests for is_error_code and is_error_condition, since they were really lacking. Thanks to Alisdair for the heads-up that we were missing these. Added: libcxx/trunk/test/std/diagnostics/syserr/is_error_code_enum.pass.cpp libcxx/trunk/test/std/diagnostics/syserr/is_error_condition_enum.pass.cpp libcxx/trunk/test/std/input.output/iostreams.base/is_error_code_enum_io_errc.pass.cpp Modified: libcxx/trunk/include/system_error libcxx/trunk/test/std/thread/futures/futures.overview/is_error_code_enum_future_errc.pass.cpp Modified: libcxx/trunk/include/system_error URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/system_error?rev=282331&r1=282330&r2=282331&view=diff == --- libcxx/trunk/include/system_error (original) +++ libcxx/trunk/include/system_error Sat Sep 24 12:36:14 2016 @@ -46,6 +46,12 @@ template struct is_error_code_ template struct is_error_condition_enum : public false_type {}; +template +constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17 + +template +constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17 + class error_code { public: @@ -236,12 +242,22 @@ template struct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum : public false_type {}; +#if _LIBCPP_STD_VER > 14 +template +constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; +#endif + // is_error_condition_enum template struct _LIBCPP_TYPE_VIS_ONLY is_error_condition_enum : public false_type {}; +#if _LIBCPP_STD_VER > 14 +template +constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; +#endif + // Some error codes are not present on all platforms, so we provide equivalents // for them: Added: libcxx/trunk/test/std/diagnostics/syserr/is_error_code_enum.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/diagnostics/syserr/is_error_code_enum.pass.cpp?rev=282331&view=auto == --- libcxx/trunk/test/std/diagnostics/syserr/is_error_code_enum.pass.cpp (added) +++ libcxx/trunk/test/std/diagnostics/syserr/is_error_code_enum.pass.cpp Sat Sep 24 12:36:14 2016 @@ -0,0 +1,51 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// +// +// UNSUPPORTED: c++03 + +// + +// template <> struct is_error_code_enum<> : public false_type {}; + +#include +#include +#include "test_macros.h" + +template +void +test() +{ +static_assert((std::is_error_code_enum::value == Expected), ""); +#if TEST_STD_VER > 14 +static_assert((std::is_error_code_enum_v == Expected), ""); +#endif +} + +class A { + A(); + operator std::error_code () const { return std::error_code(); } +}; + +// Specialize the template for my class +namespace std +{ + template <> + struct is_error_code_enum : public std::true_type {}; +} + + +int main() +{ +test(); +test(); +test(); +test(); + +test(); +} Added: libcxx/trunk/test/std/diagnostics/syserr/is_error_condition_enum.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/diagnostics/syserr/is_error_condition_enum.pass.cpp?rev=282331&view=auto == --- libcxx/trunk/test/std/diagnostics/syserr/is_error_condition_enum.pass.cpp (added) +++ libcxx/trunk/test/std/diagnostics/syserr/is_error_condition_enum.pass.cpp Sat Sep 24 12:36:14 2016 @@ -0,0 +1,51 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// template constexpr bool is_error_condition_enum_v; + +#include +#include +#include "test_macros.h" + +template +void +test() +{ +static_assert((std::is_error_condition_enum::value == Expected), ""); +#if TEST_STD_VER > 14 +static_assert((std::is_error_condition_enum_v== Expected), ""); +#endif +} + +class A { + A(); + operator std::error_condition () const { return std::error_condition(); } +}; + +// Specialize the template for my class +namespa
Re: [PATCH] D24845: [clang-tidy] fix for NOLINT after macro expansion
This revision was automatically updated to reflect the committed changes. Closed by commit rL282330: [clang-tidy] fix for NOLINT after macro expansion (authored by mgehre). Changed prior to commit: https://reviews.llvm.org/D24845?vs=72214&id=72391#toc Repository: rL LLVM https://reviews.llvm.org/D24845 Files: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp clang-tools-extra/trunk/test/clang-tidy/nolint.cpp Index: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp === --- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp @@ -294,12 +294,24 @@ return false; } +static bool LineIsMarkedWithNOLINTinMacro(SourceManager &SM, + SourceLocation Loc) { + while (true) { +if (LineIsMarkedWithNOLINT(SM, Loc)) + return true; +if (!Loc.isMacroID()) + return false; +Loc = SM.getImmediateExpansionRange(Loc).first; + } + return false; +} + void ClangTidyDiagnosticConsumer::HandleDiagnostic( DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) { if (Info.getLocation().isValid() && DiagLevel != DiagnosticsEngine::Error && DiagLevel != DiagnosticsEngine::Fatal && - LineIsMarkedWithNOLINT(Diags->getSourceManager(), Info.getLocation())) { + LineIsMarkedWithNOLINTinMacro(Diags->getSourceManager(), Info.getLocation())) { ++Context.Stats.ErrorsIgnoredNOLINT; return; } Index: clang-tools-extra/trunk/test/clang-tidy/nolint.cpp === --- clang-tools-extra/trunk/test/clang-tidy/nolint.cpp +++ clang-tools-extra/trunk/test/clang-tidy/nolint.cpp @@ -13,4 +13,18 @@ int j; // NOLINT } -// CHECK-MESSAGES: Suppressed 3 warnings (3 NOLINT) +#define MACRO(X) class X { X(int i); }; +MACRO(D) +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: single-argument constructors must be marked explicit +MACRO(E) // NOLINT + +#define MACRO_NOARG class F { F(int i); }; +MACRO_NOARG // NOLINT + +#define MACRO_NOLINT class G { G(int i); }; // NOLINT +MACRO_NOLINT + +#define DOUBLE_MACRO MACRO(H) // NOLINT +DOUBLE_MACRO + +// CHECK-MESSAGES: Suppressed 7 warnings (7 NOLINT) Index: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp === --- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp @@ -294,12 +294,24 @@ return false; } +static bool LineIsMarkedWithNOLINTinMacro(SourceManager &SM, + SourceLocation Loc) { + while (true) { +if (LineIsMarkedWithNOLINT(SM, Loc)) + return true; +if (!Loc.isMacroID()) + return false; +Loc = SM.getImmediateExpansionRange(Loc).first; + } + return false; +} + void ClangTidyDiagnosticConsumer::HandleDiagnostic( DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) { if (Info.getLocation().isValid() && DiagLevel != DiagnosticsEngine::Error && DiagLevel != DiagnosticsEngine::Fatal && - LineIsMarkedWithNOLINT(Diags->getSourceManager(), Info.getLocation())) { + LineIsMarkedWithNOLINTinMacro(Diags->getSourceManager(), Info.getLocation())) { ++Context.Stats.ErrorsIgnoredNOLINT; return; } Index: clang-tools-extra/trunk/test/clang-tidy/nolint.cpp === --- clang-tools-extra/trunk/test/clang-tidy/nolint.cpp +++ clang-tools-extra/trunk/test/clang-tidy/nolint.cpp @@ -13,4 +13,18 @@ int j; // NOLINT } -// CHECK-MESSAGES: Suppressed 3 warnings (3 NOLINT) +#define MACRO(X) class X { X(int i); }; +MACRO(D) +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: single-argument constructors must be marked explicit +MACRO(E) // NOLINT + +#define MACRO_NOARG class F { F(int i); }; +MACRO_NOARG // NOLINT + +#define MACRO_NOLINT class G { G(int i); }; // NOLINT +MACRO_NOLINT + +#define DOUBLE_MACRO MACRO(H) // NOLINT +DOUBLE_MACRO + +// CHECK-MESSAGES: Suppressed 7 warnings (7 NOLINT) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r282330 - [clang-tidy] fix for NOLINT after macro expansion
Author: mgehre Date: Sat Sep 24 11:06:53 2016 New Revision: 282330 URL: http://llvm.org/viewvc/llvm-project?rev=282330&view=rev Log: [clang-tidy] fix for NOLINT after macro expansion Summary: When having ``` c++ #define MACRO code-with-warning MACRO; // NOLINT ``` clang-tidy would still show the warning, because it searched for "NOLINT" only in the first line, not on the second. This caused e.g. https://llvm.org/bugs/show_bug.cgi?id=29089 (where the macro was defined in a system header). See also the added test cases. Now clang-tidy looks at the line of macro invocation and every line of macro definition for a NOLINT comment. Reviewers: alexfh, aaron.ballman, hokein Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D24845 Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp clang-tools-extra/trunk/test/clang-tidy/nolint.cpp Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp?rev=282330&r1=282329&r2=282330&view=diff == --- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Sat Sep 24 11:06:53 2016 @@ -294,12 +294,24 @@ static bool LineIsMarkedWithNOLINT(Sourc return false; } +static bool LineIsMarkedWithNOLINTinMacro(SourceManager &SM, + SourceLocation Loc) { + while (true) { +if (LineIsMarkedWithNOLINT(SM, Loc)) + return true; +if (!Loc.isMacroID()) + return false; +Loc = SM.getImmediateExpansionRange(Loc).first; + } + return false; +} + void ClangTidyDiagnosticConsumer::HandleDiagnostic( DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) { if (Info.getLocation().isValid() && DiagLevel != DiagnosticsEngine::Error && DiagLevel != DiagnosticsEngine::Fatal && - LineIsMarkedWithNOLINT(Diags->getSourceManager(), Info.getLocation())) { + LineIsMarkedWithNOLINTinMacro(Diags->getSourceManager(), Info.getLocation())) { ++Context.Stats.ErrorsIgnoredNOLINT; return; } Modified: clang-tools-extra/trunk/test/clang-tidy/nolint.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/nolint.cpp?rev=282330&r1=282329&r2=282330&view=diff == --- clang-tools-extra/trunk/test/clang-tidy/nolint.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/nolint.cpp Sat Sep 24 11:06:53 2016 @@ -13,4 +13,18 @@ void f() { int j; // NOLINT } -// CHECK-MESSAGES: Suppressed 3 warnings (3 NOLINT) +#define MACRO(X) class X { X(int i); }; +MACRO(D) +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: single-argument constructors must be marked explicit +MACRO(E) // NOLINT + +#define MACRO_NOARG class F { F(int i); }; +MACRO_NOARG // NOLINT + +#define MACRO_NOLINT class G { G(int i); }; // NOLINT +MACRO_NOLINT + +#define DOUBLE_MACRO MACRO(H) // NOLINT +DOUBLE_MACRO + +// CHECK-MESSAGES: Suppressed 7 warnings (7 NOLINT) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24884: Fix PR30274
arphaman abandoned this revision. arphaman added a comment. I just noticed that PR 30274 is actually a duplicate of PR 29087, which already has a patch with a fix in review. This patch is now abandoned. Sorry about not noticing the duplicate earlier. Repository: rL LLVM https://reviews.llvm.org/D24884 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Patch for issue #22924
This patch address issue 22924. Context of the issue: -- Currently code $ cat bad-init.cpp class A { public: A(int a): i_(a) {} int i_ = 0; }; void foo() { A *p = new A[2] { A(3), A(5) }; } is rejected with error bad-init.cpp:8:36: error: no matching constructor for initialization of 'A' A *p = new A[2] { A(3), A(5) }; Some arguments in defence of this behaviour is that standard is not completely clear in [expr.new] p19. In fact I was defending it as well, when we discussed this case in our local cpp community. But there was a disagreement on this mater, also it was pointed out that clang ignores array size in new[] (see below), thus it allows producing ill-formed code for aggregate initialisation. Keeping this behaviour intact produces inconsistency because: 1) Ill-formed code shouldn't be accepted by compiler. 2) A *p = new A { A(1) }; // compiles fine in clang. 3) It differs from array initialisation: A a[2] { {1}, {2} }; // compiles fine. 4) Other mainline compilers treat this code as valid. 5) clang backend itself produces code not using default constructor in the following example: $ cat good-init.cpp class A { public: A() {} A(int a): i_(a) {} int i_; }; void foo() { A *p = new A[2] { A(3), A(5) }; } $ clang++ -cc1 --std=c++11 -emit-llvm ./good-init.cpp; cat ./good-init.ll | grep "foo" -A 11 define void @_Z3foov() #0 { %p = alloca %class.A*, align 8 %1 = call noalias i8* @_Znam(i64 8) #2 %2 = bitcast i8* %1 to %class.A* call void @_ZN1AC1Ei(%class.A* %2, i32 3) %3 = getelementptr inbounds %class.A, %class.A* %2, i64 1 call void @_ZN1AC1Ei(%class.A* %3, i32 5) %4 = getelementptr inbounds %class.A, %class.A* %3, i64 1 store %class.A* %2, %class.A** %p, align 8 ret void } It seems that rejection of code written in bad-init.cpp is not caused by interpretation of standard at all. Roots of the issue are in a way Sema::BuildCXXNew() handles initialiser list for arrays. It is possible in clang to compile this code without any errors: int *p = new int[2] { 1, 2, 3 }; Moreover, AST produced by parsing int *p = new int[2] { 1, 2 }; reveals interesting fact: |-VarDecl 0x10387e600 <./test.cpp:1:1, col:28> col:6 p 'int *' cinit | `-CXXNewExpr 0x10387ee00 'int *' array Function 0x10387e8f0 'operator new[]' 'void *(unsigned long)' | |-IntegerLiteral 0x10387e6a0 'int' 2 | `-InitListExpr 0x10387ed98 'int [3]' | |-array filler | | `-ImplicitValueInitExpr 0x10387edf0 <> 'int' | |-IntegerLiteral 0x10387e6c0 'int' 1 | `-IntegerLiteral 0x10387e6e0 'int' 2 It treats int[2] as int[3] (note: 3 = 1 + number of elements in initialiser lists). As result array filler appears out of nowhere. Emitted code contains 3 (three) constructor calls, although those objects have no chance to be constructed because new is called with all-ones value, thus with libcxx on my machine it produces std::bad_alloc in runtime (although I’d expect std::bad_array_new_length). In brief, clang fails to compile code written in bad-init.cpp because default constructor used as array filler initialiser is absent. Array filler shouldn’t be used if number of initialisers is equal to a number of array elements. Attached file 22924.patch addresses this by changing way of handling arrays with size specified by integer constant expressions. The changes are: * no array fillers are generated for a code similar to mentioned above. * error is reported if number of initialisers for an array is bigger than a number of that array elements. Some notable differences in compiler diagnostic output are posted in http://pastebin.com/2cNHf1kq Patch passes all clang-test regression tests except: 1) CodeGenCXX/new-array-init.cpp, because it contains excess number of initialisers which is treated as error after applying this patch: CodeGenCXX/new-array-init.cpp:18:3: error: excess elements in array 'new' initialiser new int[2] { 1, 2, 3 }; I believe this error report is correct. That means test case const_underflow() should be removed, emitting code for underflow cases makes sense only if size is not constant expression known at compile-time. 2) SemaCXX/new-delete-cxx0x.cpp, because it explicitly rejects code which is valid after applying patch. Basically this test contains simplified version of the code sample from bad-init.cpp. Therefore, I’ve updated those tests as well (see attached 22924-tests.patch). — Best regards, Alexey Tarasov 22924-tests.patch Description: Binary data 22924.patch Description: Binary data ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D23236: When ARC is enabled, no warning will be generated when a method1. Returns 'nil' in a method that is attributed to return a 'nonnull'2. The return-statement is a ConditionalOperator
parallaxe added a comment. Uhm, is there something missing from my side that i have overseen to go forward with this patch? https://reviews.llvm.org/D23236 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D14326: ASTImporter: expressions, pt.2
a.sidorin added a comment. Don't hurry. The segfault is fixed already and patch waits for approval: https://reviews.llvm.org/D24807. I'll update this fix in Monday. https://reviews.llvm.org/D14326 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits