-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA14-8-2.cpp
More file actions
73 lines (51 loc) · 1.11 KB
/
A14-8-2.cpp
File metadata and controls
73 lines (51 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Rule: A14-8-2
// Source line: 21269
// Original file: A14-8-2.cpp
// $Id: A14-8-2.cpp 312698 2018-03-21 13:17:36Z michal.szczepankiewicz $
#include <cstdint>
#include <memory>
#include <iostream>
template<typename T>
void F1(T t)
{
//compliant, (a)
std::cout << "(a)" << std::endl;
}
template<>
void F1<>(uint16_t* p)
{
//non-compliant
//(x), explicit specialization of
//(a), not (b), due to declaration
//order
std::cout << "(x)" << std::endl;
}
template<typename T>
void F1(T* p)
{
//compliant, (b), overloads (a)
std::cout << "(b)" << std::endl;
}
template<>
void F1<>(uint8_t* p)
{
//non-compliant
//(c), explicit specialization of (b)
std::cout << "(c)" << std::endl;
}
void F1(uint8_t* p)
{
//compliant
//(d), plain function, overloads with (a), (b)
//but not with (c)
std::cout << "(d)" << std::endl;
}
int main(void)
{
auto sp8 = std::make_unique<uint8_t>(3);
auto sp16 = std::make_unique<uint16_t>(3);
F1(sp8.get()); //calls (d), which might be
//confusing, but (c) is non-compliant
F1(sp16.get()); //calls (b), which might be
//confusing, but (b) is non-compliant
}