Skip to content
Snippets Groups Projects

Fix clang -Wpotentially-evaluated-expression warning

Merged Marco Clemencic requested to merge clemenci/Gaudi:fix-clang-warnings into master
All threads resolved!

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

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Gerhard Raven resolved all threads

    resolved all threads

  • Marco Clemencic mentioned in commit 06b53b72

    mentioned in commit 06b53b72

  • Please register or sign in to reply
    Loading