{"record":{"id":"00d1328b66eca15a","repo":"stride3d/stride","slug":"cannot-redefine-name-defined","errorCode":null,"errorMessage":"Cannot redefine name 'defined'","messagePattern":"Cannot redefine name 'defined'","errorType":"exception","errorClass":"LexerException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/CppNet/Preprocessor.cs","lineNumber":331,"sourceCode":"\t *\n\t * @see #warning(int, int, String)\n\t */\n\tprotected void warning(Token tok, String msg) {\n\t\twarning(tok.getLine(), tok.getColumn(), msg);\n\t}\n\n\t/**\n\t * Adds a Macro to this Preprocessor.\n\t *\n\t * The given {@link Macro} object encapsulates both the name\n\t * and the expansion.\n\t */\n\tpublic void addMacro(Macro m) {\n\t\t// System.out.println(\"Macro \" + m);\n\t\tString\tname = m.getName();\n\t\t/* Already handled as a source error in macro(). */\n\t\tif (\"defined\" == name)\n\t\t\tthrow new LexerException(\"Cannot redefine name 'defined'\");\n\t\tmacros[m.getName()] = m;\n\t}\n\n\t/**\n\t * Defines the given name as a macro.\n\t *\n\t * The String value is lexed into a token stream, which is\n\t * used as the macro expansion.\n\t */\n\tpublic void addMacro(String name, String value) {\n\t\ttry {\n\t\t\tMacro\t\t\t\tm = new Macro(name);\n\t\t\tStringLexerSource\ts = new StringLexerSource(value);\n\t\t\tfor (;;) {\n\t\t\t\tToken\ttok = s.token();\n                if(tok.getType() == Token.EOF)\n\t\t\t\t\tbreak;\n\t\t\t\tm.addToken(tok);","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/CppNet/Preprocessor.cs#L313-L349","documentation":"addMacro() refuses to install any macro named 'defined' because 'defined' is the reserved operator used in #if expressions; redefining it would corrupt conditional-evaluation logic. The same check exists for macros created via define().","triggerScenarios":"Calling preprocessor.addMacro(new Macro(\"defined\"...)) or preprocessor.define(\"defined\", ...) — typically via a #define defined ... line or programmatic macro setup.","commonSituations":"Ported C/C++ headers that (illegally) #define defined; generated code that emits macro tables blindly; users attempting to make 'defined' behave as a constant.","solutions":["Remove the #define of 'defined' from the shader/header source","Rename the macro to any other identifier","Filter macro lists before calling addMacro to skip the reserved name"],"exampleFix":"// before\npp.define(\"defined\", \"1\");\n// after\nif (name != \"defined\") pp.define(name, \"1\");","handlingStrategy":"validation","validationCode":"if (macroName == \"defined\") throw new ArgumentException(\"'defined' is a reserved preprocessor operator\");","typeGuard":null,"tryCatchPattern":"try { pp.addMacro(m); } catch (LexerException e) { log.Error($\"Rejected macro: {e.Message}\"); }","preventionTips":["Never #define defined in shader headers","Filter macro tables from ported C/C++ code before registering"],"tags":["shader","preprocessor","macro"],"backgroundTag":"invalid-identifier","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}