blob: 064b56f7ac69d0b352aa2b8f69c77bc8a4bddea2 (
plain)
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
|
#include <iostream>
/*
*
* 6.30
*
*
*/
/*
bool str_subrange(const std::string &str1, const std::string &str2)
{
// same sizes: return normal equality test
if (str1.size() == str2.size())
return str1 == str2;
// ok: == returns bool
// find the size of the smaller string; conditional operator, see ยง 4.7 (p. 151)
auto size = (str1.size() < str2.size())
? str1.size() : str2.size();
// look at each element up to the size of the smaller string
for (decltype(size) i = 0; i != size; ++i) {
if (str1[i] != str2[i])
return; // error #1: no return value; compiler should detect this error
}
// error #2: control might flow off the end of the function without a return
// the compiler might not detect this error
}
*/
int main () {
// Tested both with clang++ and g++ and both detected the error
return 0;
}
|