Skip to content

Fix clang -Wpotentially-evaluated-expression warning

Marco Clemencic requested to merge clemenci/Gaudi:fix-clang-warnings into master

With clang something like

std::unique_ptr<SomeBase> object{new SomeDerivation{}};
std::cout << typeid(*object).name() << '\n';

results in a warning like:

warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression] which is correct.

The fix is to change the code as:

std::unique_ptr<SomeBase> object{new SomeDerivation{}};
auto bare_ptr = object.get();
std::cout << typeid(*bare_ptr).name() << '\n';

i.e. make the evaluation explicit (since it's wanted).

Edited by Marco Clemencic

Merge request reports