Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix archlinux compilation by fixing error-warnings ignored qualifiers and implicit fallthrough #3270

Merged
merged 1 commit into from
Jun 9, 2018
Merged

Fix archlinux compilation by fixing error-warnings ignored qualifiers and implicit fallthrough #3270

merged 1 commit into from
Jun 9, 2018

Conversation

berserkingyadis
Copy link
Contributor

@berserkingyadis berserkingyadis commented May 31, 2018

Related Ticket(s)

Short roundup of the initial problem

Compiling the newest Cockatrice fails under Archlinux. These are the cmake options I have used:

-DCMAKE_BUILD_TYPE=Debug -DWITH_SERVER=1

Output:
https://hastebin.com/ajahasacow.rb
https://hastebin.com/esigarajun.vbs

What will change with this Pull Request?

  • The code will be fixed, so that these warnings will no longer occur.
  • Archlinux will be able to compile in Debug mode

@Daenyth
Copy link
Member

Daenyth commented May 31, 2018

How bad is it to fix ignored-qualifiers rather than ignoring it?

@berserkingyadis
Copy link
Contributor Author

Ill post the ignored-qualifiers warnings in here, dunno how many there are.

@berserkingyadis
Copy link
Contributor Author

There are 2 warnings each.

implicit-fallthrough:

/home/bers/Projects/contrib/Cockatrice/cockatrice/src/gamesmodel.cpp: In member function ‘virtual QVariant GamesModel::headerData(int, Qt::Orientation, int) const’:
/home/bers/Projects/contrib/Cockatrice/cockatrice/src/gamesmodel.cpp:194:13: warning: this statement may fall through [-Wimplicit-fallthrough=]
             switch (role) {
             ^~~~~~
/home/bers/Projects/contrib/Cockatrice/cockatrice/src/gamesmodel.cpp:201:9: note: here
         case DESCRIPTION:
         ^~~~
/home/bers/Projects/contrib/Cockatrice/cockatrice/src/gamesmodel.cpp:210:13: warning: this statement may fall through [-Wimplicit-fallthrough=]
             switch (role) {
             ^~~~~~
/home/bers/Projects/contrib/Cockatrice/cockatrice/src/gamesmodel.cpp:217:9: note: here
         case SPECTATORS:
         ^~~~

(only 2 in the whole project?)

ignored-qualifiers:

/home/bers/Projects/contrib/Cockatrice/cockatrice/src/carditem.cpp: In member function ‘virtual void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent*)’:
/home/bers/Projects/contrib/Cockatrice/cockatrice/src/carditem.cpp:320:89: warning: type qualifiers ignored on cast result type [-Wignored-qualifiers]
             const ZoneViewZone *const view = static_cast<const ZoneViewZone *const>(zone);
                                                                                         ^
/home/bers/Projects/contrib/Cockatrice/cockatrice/src/tab_game.cpp: In member function ‘void TabGame::eventPlayerPropertiesChanged(const Event_PlayerPropertiesChanged&, int, const GameEventContext&)’:
/home/bers/Projects/contrib/Cockatrice/cockatrice/src/tab_game.cpp:1032:81: warning: type qualifiers ignored on cast result type [-Wignored-qualifiers]
         static_cast<const GameEventContext::ContextType>(getPbExtension(context));
                                                                                 ^

Seeing that there are only 2 warnings each, one could fix these imo.

(all warnings when compiling: https://pastebin.com/tfxaitET)

@berserkingyadis
Copy link
Contributor Author

I do not have the knowledge to fix the ignored-qualifiers warnings, can somebody help?

@Daenyth
Copy link
Member

Daenyth commented Jun 2, 2018

I think it's just removing some of the const. @ctrlaltca ?

@ctrlaltca
Copy link
Contributor

This could use the workaround of #3275.
Of course the real solution is to fix the code; sorry but i have no gcc 8.1 available yet to test.

@berserkingyadis
Copy link
Contributor Author

berserkingyadis commented Jun 5, 2018

I fixed the 2 warnings for ignored-qualifiers and added an exception for implicit-fallthrough, since break-less switches are used intentionally (#3240 (comment)).

Is this PR ok like this?

@@ -317,7 +317,7 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
2 * QApplication::startDragDistance())
return;
if (zone->getIsView()) {
const ZoneViewZone *const view = static_cast<const ZoneViewZone *const>(zone);
const ZoneViewZone *view = static_cast<const ZoneViewZone *>(zone);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the const from the pointer since the type of zone is non-const pointer.

CardZone *zone;
that should have been the issue.

@ctrlaltca
Copy link
Contributor

ctrlaltca commented Jun 5, 2018

c++17 adds a [[fallthrough]] statement that can be used to inform the compiler that the fallthrough is intentional.
Since we currently only support c++11, only compiler-specific statements can be used. Here's how mozilla is dealing with these, maybe it can be an inspiration:

#ifndef __has_cpp_attribute
#  define __has_cpp_attribute(x) 0
#endif

#if __has_cpp_attribute(clang::fallthrough)
#  define MOZ_FALLTHROUGH [[clang::fallthrough]]
#elif __has_cpp_attribute(gnu::fallthrough)
#  define MOZ_FALLTHROUGH [[gnu::fallthrough]]
#elif defined(_MSC_VER)
    /*
     * MSVC's __fallthrough annotations are checked by /analyze (Code Analysis):
     * https://msdn.microsoft.com/en-us/library/ms235402%28VS.80%29.aspx
     */
#  include <sal.h>
#  define MOZ_FALLTHROUGH __fallthrough
#else
#  define MOZ_FALLTHROUGH /* FALLTHROUGH */
#endif

usage

switch(test)
{
	case 1:
		break;
	case 2:
		MOZ_FALLTHROUGH
	default:
		break;
}

@berserkingyadis
Copy link
Contributor Author

where should I add the MOZ_FALLTHROUGH macro? a new header file?

@ctrlaltca
Copy link
Contributor

a new header file?

Yep, that's the idea, and then #include "newfile.h" only where needed

@berserkingyadis
Copy link
Contributor Author

berserkingyadis commented Jun 5, 2018

That is working. (Sorry for the many edits)

We should credit the mozilla guys for the macro right?

@berserkingyadis
Copy link
Contributor Author

That should do it, the macro should be tested on other platforms (clang, osx, windows)

Both warnings are fixed in the code, CMakeLists.txt remains untouched.

@berserkingyadis berserkingyadis changed the title [WIP] Fix archlinux compilation by adding warning-error exceptions Fix archlinux compilation by adding warning-error exceptions Jun 5, 2018
@@ -197,6 +198,7 @@ QVariant GamesModel::headerData(int section, Qt::Orientation /*orientation*/, in
case Qt::TextAlignmentRole:
return Qt::AlignCenter;
}
SWITCH_FALLTHROUGH;
Copy link
Contributor

@ctrlaltca ctrlaltca Jun 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry i didn't look at the code before bringing up the MOZ_FALLTHROUGH topic, but here a simple break; would have avoided the warning without the need of adding a new header file.
To be precise, we don't want it to fall through.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the other switch statement is the same I could just add a break there too. Remove the header file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, sorry again for the wasted time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding a break in these places makes the compiler think that the control could reach the end of the function error: control reaches end of non-void function [-Werror=return-type]

since the switch defaults to return QVariant(); I think ill add it at the end of the function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another idea would be adding default cases to both the switches returning QVariant(), this is done alot in the function above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or, you can add return QVariant() in place of the breaks

@berserkingyadis
Copy link
Contributor Author

ok, added the defaults to the switches

@tooomm
Copy link
Member

tooomm commented Jun 7, 2018

Can you update your starting post? @berserkingyadis

@berserkingyadis berserkingyadis changed the title Fix archlinux compilation by adding warning-error exceptions Fix archlinux compilation by fixing error-warnings ignored qualifiers and implicit fallthrough Jun 7, 2018
@berserkingyadis
Copy link
Contributor Author

updated, should reflect the changes now.

@ctrlaltca ctrlaltca merged commit 91b3c73 into Cockatrice:master Jun 9, 2018
@ctrlaltca
Copy link
Contributor

Merged, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compilation on Archlinux fails because of missing break statements
4 participants