OpenAPITools / OpenAPITools/openapi-generator

[REQ] [C++][Pistache] Header guards not unique

Open
#4,220 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

The code generated by the C++ pistache generator includes header guards in each header. The name of these header guards are based only on the class contained within the header. E.g.:

#ifndef Animal_H_
#define Animal_H_

namespace a {
namespace b {

class Animal {
};

}
}

#endif /* Animal_H_ */

Such header guards can easily conflict with guards in existing code (which could come from another library, e.g. imagine a class named vector, which exists in tons of libraries).

I would suggest including at least each of the namespaces in the header guard variable's name (i.e. #ifndef a_b_Animal_H_). Or, IMHO even better, use #pragma once which avoids the whole issue altogether.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the C++ Pistache generator templates or entry points that emit header guards, then inspect generated headers like the Animal example. Confirm that guards remain unique when classes share names across namespaces; done means the generated guards include sufficient namespace context or use pragma once, with the resulting generated output checked for conflicts.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.