相关疑难解决方法(0)

gcc或clang对此行为是否正确?

我有一个小玩具程序:

static int value = 0;

int function(int &value=value) {
    return value;
}

int main() {
    function();
}
Run Code Online (Sandbox Code Playgroud)

使用g ++ 7.2进行编译:

g ++ -std = c ++ 11 -Wall -Wextra test.cc -o test

没问题.

用clang ++编译 - 3.9:

clang ++ - 3.9 -std = c ++ 11 -Wall -Wextra test.cc -o test

test.cc:3:25: error: default argument references parameter 'value'
int function(int &value=value) {
                        ^~~~~
test.cc:8:5: error: no matching function for call to 'function'
    function();
    ^~~~~~~~
test.cc:3:5: note: candidate function not …
Run Code Online (Sandbox Code Playgroud)

c++ gcc clang language-lawyer c++11

38
推荐指数
3
解决办法
2568
查看次数

标签 统计

c++ ×1

c++11 ×1

clang ×1

gcc ×1

language-lawyer ×1