D is trying to parse C and C++ inside strings
max haughton
maxhaton at gmail.com
Sat Mar 18 03:22:28 UTC 2023
On Saturday, 18 March 2023 at 03:00:46 UTC, Hipreme wrote:
> I'm writing Metal shaders right now on my engine and I got the
> following warning (I use warn as errors so this is giving me
> nuts as I'll need to refactor my code to hide that string)
>
>
> ```d
> string getCoolString()
> {
> return q{
> #include <metal_stdlib>
> #include <simd/simd.h>
> using namespace metal;
> };
> }
>
> void main()
> {
> writeln(getCoolString);
> }
> ```
>
> In the run.dlang, I get the following error:
>
> ```
> Error: d++ cannot find file path for header 'metal_stdlib'
> Error Program exited with code 1
> ```
>
> In my code, I'm getting the following error:
>
> ```d
> override string getFrameBufferVertex()
> {
> return q{
> #include <metal_stdlib>
> #include <simd/simd.h>
>
> using namespace metal;
>
> struct VertexInput
> {
> float2 vPosition;
> float2 vTexST;
> };
> struct FragmentInput
> {
> ///Unused
> float4 position [[position]];
> float2 inTexST;
> };
>
> vertex FragmentInput vertex_main(
> uint vertexID [[vertex_id]],
> VertexInput* input [[buffer(1)]]
> )
> {
> FragmentInput out;
> out.position = float4(input[vertexID].vPosition, 0.0, 1.0);
> out.inTexST = input[vertexID].vTexST;
> return out;
> }
> };
> }
>
> ```
> modules/renderer/source/hip/hiprenderer/backend/metal/mtlshader.d(104,9): Warning: C preprocessor directive `#include` is not supported
>
> This looks like related to use token string.
It's parsing (lexing, even), not trying to parse, D inside the q
string literal and the D lexer spits out a warning when it sees
#include.
This arguably could be considered a bug inside a q string these
days given that their original reason for existing has gone away
quite significantly as far as I know.
More information about the Digitalmars-d
mailing list