Skip to content

Fix potential ODR violation#173

Closed
shewitt-au wants to merge 1 commit into
WerWolv:masterfrom
shewitt-au:possible_odr_violation
Closed

Fix potential ODR violation#173
shewitt-au wants to merge 1 commit into
WerWolv:masterfrom
shewitt-au:possible_odr_violation

Conversation

@shewitt-au
Copy link
Copy Markdown
Contributor

@shewitt-au shewitt-au commented Jun 17, 2025

I think there's potential for ODR violations in "lib/include/pl/core/tokens.hpp".

Here's an example:

namespace Keyword {

        Token makeKeyword(const Token::Keyword& keyword, const std::string_view& name) {
            auto token = makeToken(core::Token::Type::Keyword, keyword);
            Token::Keywords()[name] = token;
            return token;
        }

        const auto If           = makeKeyword(Token::Keyword::If, "if"); // <--- Here

Shouldn't this be:

namespace Keyword {

        inline Token makeKeyword(const Token::Keyword& keyword, const std::string_view& name) {
            auto token = makeToken(core::Token::Type::Keyword, keyword);
            Token::Keywords()[name] = token;
            return token;
        }

        inline const auto If           = makeKeyword(Token::Keyword::If, "if");
        ------

I'm new to modern C++. Last time I was a progammer for a living MVSC6 was a thing, so apologies if I'm off the mark. My outdated knowledge is what made this issue, if it is one, stand out.

I waded through standards. It seems a the inline specifier can be applied to variables as well as to functions. This would seem to remove the danger of vioilating the ODR.

I guess it's not an ODR violation in the strict sense if the definitions are identical, but to me it looks ill-formed because it violates the rule requiring only one definition of an object with external linkage — unless it is declared inline.

Sorry if the ODR claim is misleading. I'm not sure how to properly classify this.

@shewitt-au shewitt-au marked this pull request as ready for review June 17, 2025 17:32
@shewitt-au shewitt-au closed this Jun 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant