Skip to content

syntax error caused by unconditional __has_include usage #439

Description

@firewave

Encountered while working on #438.

#if __has_include(<sys/single_threaded.h>)
# include <sys/single_threaded.h>
#endif
a.cpp:1: syntax error: failed to evaluate #if condition, division/modulo by zero

Activity

  1. self-assigned this
    on Jun 12, 2025
  2. firewave commented on Jun 12, 2025

    @firewave
    CollaboratorAuthor

    It works fine when specifying -std=c++17.

    I think we should default to the latest standard by default akin to Cppcheck.

  3. ludviggunne commented on Jul 1, 2025

    @ludviggunne
    Collaborator

    I believe GCC supports __has_include for all standards, so we could also check if the standards starts with gnu....

  4. ludviggunne commented on Jul 1, 2025

    @ludviggunne
    Collaborator

    I opened #452 which I think should give a more reasonable error message when __has_include is not defined.

  5. ludviggunne commented on Jul 1, 2025

    @ludviggunne
    Collaborator

    I believe GCC supports __has_include for all standards, so we could also check if the standards starts with gnu....

    #454 addresses this

  6. added a commit that references this issue on Jul 2, 2025
    91b1a92
  7. firewave commented on Jul 3, 2025

    @firewave
    CollaboratorAuthor

    It now reports:

    a.cpp:1: syntax error: failed to evaluate #if condition, undefined function-like macro invocation: __has_include( ... )
    
  8. firewave commented on Aug 4, 2025

    @firewave
    CollaboratorAuthor

    With #454 merged it succeeds when using -std=gnu....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions