/
Page239_inline.cpp
52 lines (50 loc) · 2.19 KB
/
Page239_inline.cpp
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
// Warning: This is for verification. It CANNOT be compiled successfully by both compilers.
// The problems lie in line 8-11.
#include <iostream>
#include <string>
#include "Page239_inline.h"
using std::cout;
using std::endl;
constexpr int new_sz()
{
return 42;
}
int main()
{
cout << new_sz() << endl;
return 0;
}
// ******compile info of cl******
// 用于 x86 的 Microsoft (R) C/C++ 优化编译器 18.00.40629 版版权所有(C) Microsoft C
// orporation。 保留所有权利。
//
// Page239_inline.cpp
// Page239_inline.h(9) : error C2144: 语法错误:“int”的前面应有“;”
// Page239_inline.h(9) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++
// 不支持默认 int
// Page239_inline.cpp(8) : error C2144: 语法错误:“int”的前面应有“;”
// Page239_inline.cpp(8) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不
// 支持默认 int
// Page239_inline.cpp(8) : error C2086: “int constexpr”: 重定义
// Page239_inline.h(9) : 参见“constexpr”的声明
// Page239_inline.cpp(9) : error C2084: 函数“int new_sz(void)”已有主体
// Page239_inline.h(9) : 参见“new_sz”的前一个定义
// Page239_inline.cpp(14) : error C2568: “<<”: 无法解析函数重载
// Page239_inline.h(9): 可能是“int new_sz(void)”
// Page239_inline.cpp(14) : error C3861: “new_sz”: 找不到标识符
// ******compile info of g++******
// Page239_inline.cpp: In function 'constexpr int new_sz()':
// Page239_inline.cpp:8:15: error: redefinition of 'constexpr int new_sz()'
// constexpr int new_sz()
// ^
// In file included from Page239_inline.cpp:3:0:
// Page239_inline.h:9:15: note: 'constexpr int new_sz()' previously defined here
// constexpr int new_sz()
// ^
// Note: if line 9 to line 11 are commented, and a semicolon is appended to
// line 8:
// constexpr int new_sz();
// The program can be compiled successfully by g++, because it's just a
// redeclaration of the constexpr function new_sz(). But cl doesn't compile it
// and produce confusing error message as long as constexpr exists. Seems Visual
// Studio 2013 doesn't support constant expression function perfectly.