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

Implicit fallthrough warning/error #26

Open
howprice opened this issue Apr 29, 2024 · 3 comments
Open

Implicit fallthrough warning/error #26

howprice opened this issue Apr 29, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@howprice
Copy link

howprice commented Apr 29, 2024

I'm not sure the best way to resolve this issue in the repo, but when compiling with GCC on Ubuntu with options -Wall -Wextra -pedantic -Wno-unknown-pragmas -Werror:

In file included from /some/folder/work/myproj/myproj/src/main.cpp:20:
/home/runner/work/iragui/iragui/libs/imgui_markdown/imgui_markdown.h: In function ‘void ImGui::Markdown(const char*, size_t, const ImGui::MarkdownConfig&)’:
/home/runner/work/iragui/iragui/libs/imgui_markdown/imgui_markdown.h:726:33: error: this statement may fall through [-Werror=implicit-fallthrough=]
  726 |                                 if( em.sym == c )
      |                                 ^~
/home/runner/work/myproj/myproj/libs/imgui_markdown/imgui_markdown.h:736:25: note: here
  736 |                         case Emphasis::RIGHT:
      |                         ^~~~
cc1plus: all warnings being treated as errors

This warning can be handled in C++17 with the [[fallthrough]] attribute (in fact the linked example is almost this very case!). However, prior to C++17 unknown attributes were not guaranteed to be ignored, so using this attribute could lead to warnings with other toolchains.

I guess one messy solution might be:

#if __cplusplus >= 201703L
    [[fallthrough]]
#endif

EDIT:

Actually this fix

case Emphasis::MIDDLE:
	if( em.sym == c )
	{
		em.state = Emphasis::RIGHT;
		em.text.stop = i;
		// pass through to case Emphasis::RIGHT
		[[fallthrough]]; 
	}
	 else
	{
		break;
	}
case Emphasis::RIGHT:

Results in MSVC warning:

warning C4468: the [[fallthrough]] attribute must be followed by a case label or a default label
@dougbinks dougbinks self-assigned this May 3, 2024
@dougbinks dougbinks added the enhancement New feature or request label May 3, 2024
@dougbinks
Copy link
Member

I'm not sure what to do about this one for now, especially given the issue with the MSVC warning.

I'll have a look at it when I get time, but for now I would disable the warning before including the header.

@howprice
Copy link
Author

howprice commented May 3, 2024

Thanks. I've done that for now. Hopefully this wrinkle will flatten out over time.

@clshortfuse
Copy link

      case Emphasis::MIDDLE:
        if (em.sym != c) break;
        em.state = Emphasis::RIGHT;
        em.text.stop = i;
#if __cplusplus >= 201703L
      [[fallthrough]]
#endif
      case Emphasis::RIGHT:

This should work for Visual Studio 2017 and above: https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/

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

No branches or pull requests

3 participants