逗号运算符是否使用其参数?

mkm*_*afa 2 c++ one-definition-rule language-lawyer

根据odr-use定义,如果引用与它绑定,则对象使用odr.这就是为什么f使S :: x odr-used我相信.我无法理解的是,与逗号运算符有什么不同,它还将其参数绑定到引用参数

struct S {
    static const int x = 0; // static data member
    // a definition outside of class is required if it is odr-used
};
const int& f(const int& r);

int n = b ? (1, S::x) // S::x is not odr-used here
          : f(S::x);  // S::x is odr-used here: a definition is required
Run Code Online (Sandbox Code Playgroud)

Lig*_*ica 7

这些只是如何在类中定义重载的逗号运算符的示例.当你绑定到参数时,这种重载的使用必然会触发odr-use.

该用法尚未写入您的程序,也没有操作员在此过载.

您只是使用内置的逗号运算符.

(一个更有趣的问题可能是这个运算符的最右边的操作数是否仍然使用,因为从它看起来像我这样的措辞!请记住,生成构建不需要使用odr用途错误,在某些情况下它不会.).

我认为在这方面,cppreference页面可能有点不清楚.