3

In C++17, I have a function returning multiple values via a std::tuple and structured bindings and I wish to ignore one of the return values and suppress any warnings related to that.

I tried the following which does not compile:

[const auto [outside, [[maybe_unused]] edge, inside] = Classify();

   => error: expected identifier before '[' token

I also tried this:

[[maybe_unused]] const auto [outside, edge, inside] = Classify();

   => warning: unused variable 'edge' [-Wunused-variable]

Neither works as desired with GCC v7.3.0.

Is there a way in C++17 to neatly specify that edge is unused in a multiple value return syntax using structured bindings or is this missing from the current language definition?

Barry
  • 286,269
  • 29
  • 621
  • 977
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
  • 4
    `(void)edge;` Note that gcc 8+ doesn't warn on unused bindings at all. [Relevent](https://stackoverflow.com/q/41404001/2069064) (though probably not dupe). – Barry May 14 '19 at 21:34
  • Warnings are not part of the language, really. GCC >=8 does not warn even in C++17 mode with no attribute, so long as at least one of the bindings is used. – Davis Herring May 15 '19 at 02:57
  • 3
    As mentioned in this [answer](https://stackoverflow.com/questions/41404001/structured-binding-with-maybe-unused/55218762#55218762), this was deemed a defect in the standard, the resolution of which implied the GCC 8+ behaviour. – metalfox May 15 '19 at 07:59

0 Answers0