-
Notifications
You must be signed in to change notification settings - Fork 0
Fix build for modern C++17 and Clang 17 #1
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
Changes from all commits
8a813f1
9d3f65b
5222c99
7bed243
9cf61b1
4d1fbbf
45ad981
3f67461
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,7 +15,7 @@ namespace dotenv | |||||||||
|
|
||||||||||
| public: | ||||||||||
|
|
||||||||||
| dotenv& load_dotenv(const std::string& dotenv_path = env_filename, | ||||||||||
| dotenv& load_dotenv(const std::string& dotenv_path = ".env", | ||||||||||
| const bool overwrite = false, | ||||||||||
| const bool interpolate = true); | ||||||||||
|
|
||||||||||
|
|
@@ -28,18 +28,27 @@ namespace dotenv | |||||||||
| void operator=(const dotenv&) = delete; | ||||||||||
|
|
||||||||||
| static dotenv& instance(); | ||||||||||
|
|
||||||||||
| private: | ||||||||||
|
|
||||||||||
| dotenv() = default; | ||||||||||
|
|
||||||||||
| private: | ||||||||||
|
|
||||||||||
| // Declare static members (definitions are inline after the class) | ||||||||||
|
||||||||||
| // Declare static members (definitions are inline after the class) | |
| // Declare static members (definitions are inline after the class) | |
| // NOTE: env_filename is kept for backward compatibility; external code | |
| // may reference dotenv::dotenv::env_filename directly. |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline variable definitions on lines 47-48 conflict with the existing static member declarations on lines 38-39 (which are still in the class). When using C++17 inline variables, the static member declarations inside the class should be removed. Currently, this creates duplicate definitions that violate the One Definition Rule and will cause linker errors.
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline variable declarations for static members appear outside the class definition. According to C++17 rules, when using the inline keyword for static data members, they should still be declared (not defined) inside the class. The definitions with inline should either be inside the class body or be marked as inline at their declaration point within the class.
The current approach declares these members as non-inline static members within the class (lines 38-39) but then attempts to define them as inline outside the class. This creates a mismatch. For proper C++17 inline variables, the declaration inside the class should include the inline keyword and the initialization, like:
static inline const std::string env_filename = ".env";
static inline dotenv _instance;Then these lines 47-48 would not be needed at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default parameter has been changed from
env_filename(a static member variable) to the string literal".env". While this resolves the compilation issue and the values are equivalent, this change creates code duplication - the same string literal".env"now appears in two places (here and in the inline variable definition on line 47).If the default filename ever needs to change, it would need to be updated in both locations. Consider whether the static member
env_filenameis still necessary, or if it should be removed entirely in favor of using the literal directly in both places. Alternatively, the function signature could reference the static member once the inline variable syntax is corrected.