1
#include <upstream>
#include <future>

void test() {
    std::promise<int> m;
     int a;
}
int main(){
    test();
    return 0;
}

g++-5.4.0 —std=c++11 Wall test.cpp -o myexpect

however, a will emit a unused variable warning, m does not? is this compiler a bug?

Roamer-1888
  • 19,138
  • 5
  • 33
  • 44
mac.ma
  • 703
  • 2
  • 8
  • 22
  • `a` is an `int`, so its construction and destruction carries no side effects. `m` is a `std::promise`, which has both nontrivial constructors and destructors. The act of building and tearing down the variable itself carries real effects in your program. – Silvio Mayolo Mar 01 '22 at 03:26
  • @SilvioMayolo Then, how do we understand *unused-variable* ? – mac.ma Mar 01 '22 at 04:14
  • I know how *I* understand *unused variable*, but that is probably a bit different from what the compiler regards as unused. The compiler has to make conservative decisions in the face of potential side-effects, because it can not read my mind. – j6t Mar 01 '22 at 10:12
  • @j6t talk is cheap,show me code :) – mac.ma Mar 01 '22 at 10:27

0 Answers0