micro icon indicating copy to clipboard operation
micro copied to clipboard

False warning in C++ .hpp file

Open teodor256 opened this issue 1 year ago • 2 comments

Description of the problem or steps to reproduce

After adding "#pragma once" in empty .hpp file Micro throws warning "#pragma once in main file". It occurs even if "int main()" is not declared, which is misleading.

Specifications

Commit hash: Version: 2.0.11 OS: Debian GNU/Linux 12 (Bookworm) Terminal: Alacritty

teodor256 avatar Feb 07 '24 23:02 teodor256

Micro does not include a C++ compiler, the warning is coming from a linter or a language server you have set up. You should open the issue in their repository.

Andriamanitra avatar Feb 08 '24 09:02 Andriamanitra

I think @teodor256 did not "set up" anything. The issue is with micro's built-in linter plugin. It uses these commands for checking C or C++ files:

    makeLinter("gcc", "c", "gcc", {"-fsyntax-only", "-Wall", "-Wextra", "%f"}, "%f:%l:%c:.+: %m")
    makeLinter("g++", "c++", "gcc", {"-fsyntax-only","-std=c++14", "-Wall", "-Wextra", "%f"}, "%f:%l:%c:.+: %m")

So the problem is with gcc: it always throws #pragma once in main file if a file containing #pragma once is passed to the gcc command line, i.e. it assumes that header files should never be passed to it on the command line. Which is reasonable in normal case when compiling, but it also happens when gcc is run with -fsyntax-only. So gcc with -fsyntax-only cannot be quite reliably used for checking syntax of header files. And gcc doesn't even provide an explicit option to suppress this warning.

I see it is reported in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89808. See in particular comment https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89808#c11.

dmaluka avatar Feb 13 '24 23:02 dmaluka