# Changeset View

Changeset View

# Standalone View

Standalone View

# test/clang-tidy/misc-default-numerics.cpp

- This file was added.

1 | // RUN: %check_clang_tidy %s misc-default-numerics %t | ||||
---|---|---|---|---|---|

2 | | ||||

3 | namespace std { | ||||

4 | | ||||

5 | template <typename T> | ||||

6 | struct numeric_limit { | ||||

aaron.ballman: numeric_limits (same elsewhere in this file). | |||||

7 | static T min() { return T(); } | ||||

8 | static T max() { return T(); } | ||||

9 | }; | ||||

10 | | ||||

11 | template <> | ||||

12 | struct numeric_limit<int> { | ||||

13 | static int min() { return -1; } | ||||

14 | static int max() { return 1; } | ||||

15 | }; | ||||

16 | | ||||

17 | } // namespace std | ||||

18 | | ||||

19 | class MyType {}; | ||||

20 | template <typename T> | ||||

21 | class MyTemplate {}; | ||||

22 | | ||||

23 | void test() { | ||||

24 | auto x = std::numeric_limit<int>::min(); | ||||

25 | | ||||

26 | auto y = std::numeric_limit<MyType>::min(); | ||||

27 | // CHECK-MESSAGES: [[@LINE-1]]:12: warning: 'std::numeric_limits::min' called with type 'MyType'; no such specialization exists, so the default value for that type is returned | ||||

28 | | ||||

29 | auto z = std::numeric_limit<MyTemplate<int>>::max(); | ||||

Not Done ReplyThis is not a proper specialization according to the standard.
The functions are not marked aaron.ballman: This is not a proper specialization according to the standard.
> A program may add a template… | |||||

30 | // CHECK-MESSAGES: [[@LINE-1]]:12: warning: 'std::numeric_limits::max' called with type 'MyTemplate<int>'; | ||||

31 | } | ||||

32 | | ||||

33 | template <typename T> | ||||

Done ReplyCan you add a test case where numeric_limits has been properly specialized for the type and the type is not a builtin? aaron.ballman: Can you add a test case where numeric_limits has been properly specialized for the type and the… | |||||

34 | void fun() { | ||||

35 | auto x = std::numeric_limit<T>::min(); | ||||

36 | } | ||||

37 | | ||||

38 | void testTemplate() { | ||||

39 | fun<int>(); | ||||

40 | // FIXME: This should generate warning with backtrace. | ||||

41 | fun<MyType>; | ||||

42 | } |

numeric_limits (same elsewhere in this file).