Author Topic: automatic header guard added despite one is already existing  (Read 4707 times)

Offline J.

  • Multiple posting newcomer
  • *
  • Posts: 47
automatic header guard added despite one is already existing
« on: April 18, 2020, 03:19:05 pm »
Since one of the March 2020 Windows nightly builds - or even earlier -, header guards are automatically added to header files, regardless if there is already one in the header body further down or not.  The example below suggests that the algorithm appears to be checking the first line only (try and open the file, then make a change in the editor ... and there is an obsolete additional header guard).

Code
/** comment */

#ifndef HEADER_H_INCLUDED
#define HEADER_H_INCLUDED

#endif // HEADER_H_INCLUDED

Can this feature be switched-off somewhere, since changing to headers of packages with, e.g., a banner before the header guard always results in unneccessary changes which is pretty annoying? Still observed in Nightly build 2020-04-18.

Thanks!

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1697
Re: automatic header guard added despite one is already existing
« Reply #1 on: April 18, 2020, 03:50:50 pm »
Disable the new header guard plugin

Offline J.

  • Multiple posting newcomer
  • *
  • Posts: 47
Re: automatic header guard added despite one is already existing
« Reply #2 on: April 19, 2020, 09:53:17 am »
Great - that works!  Happy to switch the plugin on again, when it is able to cope with already existing guards.

Many thanks, Miguel! 

Offline raynebc

  • Almost regular
  • **
  • Posts: 221
Re: automatic header guard added despite one is already existing
« Reply #3 on: February 27, 2025, 06:50:02 am »
I'm finding that as of the 11-11-24 nightly build of Code::Blocks, this plugin can still behave badly.  One of my old header files had the guard placed after some comment lines and when I opened the file and made an edit in C::B, the plugin added an additional header guard of its own.  It refused to stop doing this even when I moved my own header guard to the very top of the file.  I also find that it changes the file's line break encoding from CRLF to mixed style when it alters the file.  I'm going to just disable the plugin, but it seems to need some fixing.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1697
Re: automatic header guard added despite one is already existing
« Reply #4 on: February 27, 2025, 01:56:04 pm »
I would change
Code
	if(s.StartsWith(_T("#ifndef")) && ( s.Contains(_T("HEADER")) || s.Right(2).IsSameAs(_T("_H")) || s.Contains(_T(" H_")) || s.Contains(_T("_H_")) || s.Contains(_T("_INCLUDED")) ))
return;
to just
Code
	if (s.StartsWith("#ifndef"))
return;

For the EOL part, insertion of '\n' should be replaced by calls to NewLine()