https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114461
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Oh, and I think there is another problem with that paper. module : private ; is valid, but the addition of https://eel.is/c++draft/cpp.module#2 stands in a way, the pp-tokens in that case don't match pp-module-name followed by something, the first token is :. So, : pp-tokens[opt] should be another valid form IMHO and in that case tokens after the : should be macro expanded. #define PRIVATE :private module PRIVATE; would be invalid as that clashes with the other form. I'm playing with: --- libcpp/lex.cc.jj 2024-08-07 09:38:00.950805926 +0200 +++ libcpp/lex.cc 2024-08-07 17:23:22.987862447 +0200 @@ -3538,6 +3538,72 @@ cpp_maybe_module_directive (cpp_reader * /* Maybe tell the tokenizer we expect a header-name down the road. */ pfile->state.directive_file_token = header_count; + + /* According to P3034R1, pp-module-name and pp-module-partition tokens + if any shouldn't be macro expanded and identifiers shouldn't be + defined as object-like macro. */ + if (!header_count && peek->type == CPP_NAME) + { + int state = 0; + do + { + cpp_token *tok = peek; + if (tok->type == CPP_NAME) + { + cpp_hashnode *node = tok->val.node.node; + /* Don't attempt to expand the token. */ + tok->flags |= NO_EXPAND; + if (_cpp_defined_macro_p (node) + && _cpp_maybe_notify_macro_use (pfile, node, + tok->src_loc) + && !cpp_fun_like_macro_p (node)) + { + if (state == 0) + cpp_error_with_line (pfile, CPP_DL_ERROR, + tok->src_loc, 0, + "module name \"%s\" cannot " + "be an object-like macro", + NODE_NAME (node)); + else + cpp_error_with_line (pfile, CPP_DL_ERROR, + tok->src_loc, 0, + "module partition \"%s\" cannot " + "be an object-like macro", + NODE_NAME (node)); + } + } + peek = _cpp_lex_direct (pfile); + backup++; + if (tok->type == CPP_NAME) + { + if (peek->type == CPP_DOT) + continue; + else if (peek->type == CPP_COLON && state == 0) + { + ++state; + continue; + } + else if (peek->type == CPP_OPEN_PAREN) + { + if (state == 0) + cpp_error_with_line (pfile, CPP_DL_ERROR, + peek->src_loc, 0, + "module name followed by \"(\""); + else + cpp_error_with_line (pfile, CPP_DL_ERROR, + peek->src_loc, 0, + "module partition followed by " + "\"(\""); + break; + } + else + break; + } + else if (peek->type != CPP_NAME) + break; + } + while (true); + } } else { but need to write some testcases.