Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

attribute 'fallthrough' cannot be applied in this context

I'm trying to use the c++17 [[fallthrough]] attribute in visual studio 2017:

Qt::ItemFlags flags = Qt::ItemIsSelectable;

switch (index.column())
{
case 0:
    flags |= Qt::ItemIsUserCheckable;
    break;
case 2:
    [[fallthrough]]
case 3:
    [[fallthrough]]
case 4:
    flags |= Qt::ItemIsEditable;
    break;
}
return flags;

but I get the compiler error:

attribute 'fallthrough' cannot be applied in this context

This seems like the only context where you can use [[fallthrough]]... what am I doing wrong?

like image 695
Nicolas Holthaus Avatar asked Sep 26 '17 12:09

Nicolas Holthaus


1 Answers

This cryptic error is given because [[fallthrough]] attributes require a semicolon to terminate them. Rewriting the case statement as

case 2:
    [[fallthrough]];
case 3:
    [[fallthrough]];
// ...

resolves the error.

like image 84
Nicolas Holthaus Avatar answered Nov 19 '22 06:11

Nicolas Holthaus