[Issue 21300] New: C++ header generation produce nonsense code on enum with enum as parent

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Oct 9 19:26:29 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=21300

          Issue ID: 21300
           Summary: C++ header generation produce nonsense code on enum
                    with enum as parent
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: C++
          Severity: blocker
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: pro.mathias.lang at gmail.com

Code, extracted from DMD:
```
extern(C++):

enum Color : int
{
    Blue,
    Red,
    Green,
}

enum Classification
{
    Deprecation = Color.Blue,
    Error = Color.Red,
    Tip = Color.Green,
}
```

Using master:
*   de9057ea6 - (upstream/master, origin/master, origin/HEAD, master) Merge
pull request #11805 from MoonlightSentinel/build-from-run (14 hours ago) <The
Dlang Bot>

```
// Automatically generated by Digital Mars D Compiler

#pragma once

#include <stddef.h>
#include <stdint.h>


enum class Color
{
    Blue = 0,
    Red = 1,
    Green = 2,
};

namespace Classification
{
    static Color const Deprecation = (Classification)(Color)0;
    static Color const Error = (Classification)(Color)1;
    static Color const Tip = (Classification)(Color)2;
};
```

Compiling this code:
```
In file included from foo.cpp:1:
./foobar.h:18:39: error: unexpected namespace name 'Classification': expected
expression
    static Color const Deprecation = (Classification)(Color)0;
                                      ^
./foobar.h:18:55: error: 'Color' does not refer to a value
    static Color const Deprecation = (Classification)(Color)0;
                                                      ^
./foobar.h:9:12: note: declared here
enum class Color
           ^
./foobar.h:19:33: error: unexpected namespace name 'Classification': expected
expression
    static Color const Error = (Classification)(Color)1;
                                ^
./foobar.h:19:49: error: 'Color' does not refer to a value
    static Color const Error = (Classification)(Color)1;
                                                ^
./foobar.h:9:12: note: declared here
enum class Color
           ^
./foobar.h:20:31: error: unexpected namespace name 'Classification': expected
expression
    static Color const Tip = (Classification)(Color)2;
                              ^
./foobar.h:20:47: error: 'Color' does not refer to a value
    static Color const Tip = (Classification)(Color)2;
                                              ^
./foobar.h:9:12: note: declared here
enum class Color
           ^
6 errors generated.
```

Marking as blocker since this is a pattern used in DMD, and dtoh is now
required by the CI.

--


More information about the Digitalmars-d-bugs mailing list