Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Issue 8081 - pure nothrow unittest problem in generated 'header' file #1139

Merged
merged 1 commit into from

5 participants

@braddr braddr commented on the diff
src/attrib.c
@@ -356,6 +357,10 @@ void AttribDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (decl->dim == 0)
buf->writestring("{}");
+ else if (hgs->hdrgen && decl->dim == 1 && (*decl)[0]->isUnitTestDeclaration())
+ { // hack for bugzilla 8081
+ buf->writestring("{}");
@braddr Owner
braddr added a note

Why isn't that: buf->writestring("unittest {}"); ?

@9rnsr Collaborator
9rnsr added a note

Because unittest doesn't appear in generated header file.

@braddr Owner
braddr added a note

Then, while this makes things not fail, it's not right. The entire "nothrow pure {}" shouldn't be included at all.

@9rnsr Collaborator
9rnsr added a note

Because it is difficult to implement with a little lines.
Current header generation mechanism doesn't consider unittest block which not shown in header.
And, AttributeDeclaration (and it's derived classes) can be nesting.

version(unittest) {
  pure {
    public unittest {}
    pure nothrow unittest {}
    extern(C) unittest {}
  }
}

In this case, it is hard to implement that stop displaying of whole `pure { ... }.

Then, this is a hacky change as I wrote in comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@9rnsr
Collaborator

I've updated the unittest, not only for StorageClassDeclaration, and also LinkDeclaration, ProtDeclaration, and AlignDeclaration.

@yebblies
Collaborator

Is there any reason we can't just remove the if (decl->dim == 1) special casing and always output the braces around the declarations? This wouldn't need any hacks, and would probably be more robust, at the expense of making the code slightly uglier.

@ghost

Why are unittests exported to header files anyway?

@9rnsr
Collaborator

Unittests are not exposed to header files. Just only redundant attribute scope (e.g, nothrow pure {}) will be exposed by this change. I think it should be fixed, but it needs more hard work.

@WalterBright
Owner

I suspect that this solution will just generate another bug report.

@ghost

I suspect that this solution will just generate another bug report.

No doubt about that. However the current problem is a blocker, but having empty blocks instead is just a nuisance that can be fixed later.

Perhaps leave the bug marked as not fixed after pulling this, but at least the compile errors will be gone.

@andralex andralex merged commit 23c6ac5 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
5 src/attrib.c
@@ -27,6 +27,7 @@
#include "module.h"
#include "parse.h"
#include "template.h"
+#include "hdrgen.h"
/********************************* AttribDeclaration ****************************/
@@ -337,6 +338,10 @@ void AttribDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
if (decl->dim == 0)
buf->writestring("{}");
+ else if (hgs->hdrgen && decl->dim == 1 && (*decl)[0]->isUnitTestDeclaration())
+ { // hack for bugzilla 8081
+ buf->writestring("{}");
@braddr Owner
braddr added a note

Why isn't that: buf->writestring("unittest {}"); ?

@9rnsr Collaborator
9rnsr added a note

Because unittest doesn't appear in generated header file.

@braddr Owner
braddr added a note

Then, while this makes things not fail, it's not right. The entire "nothrow pure {}" shouldn't be included at all.

@9rnsr Collaborator
9rnsr added a note

Because it is difficult to implement with a little lines.
Current header generation mechanism doesn't consider unittest block which not shown in header.
And, AttributeDeclaration (and it's derived classes) can be nesting.

version(unittest) {
  pure {
    public unittest {}
    pure nothrow unittest {}
    extern(C) unittest {}
  }
}

In this case, it is hard to implement that stop displaying of whole `pure { ... }.

Then, this is a hacky change as I wrote in comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
else if (decl->dim == 1)
((*decl)[0])->toCBuffer(buf, hgs);
else
View
8 test/compilable/extra-files/header.di
@@ -326,3 +326,11 @@ template foo6591()
}
}
+version (unittest)
+{
+ nothrow pure {}
+ nothrow pure {}
+ public {}
+ extern (C) {}
+ align{}
+}
View
11 test/compilable/header.d
@@ -349,3 +349,14 @@ void foo6591()()
{
import std.stdio : writeln, F = File;
}
+
+
+// 8081
+version(unittest) {
+ pure nothrow unittest {}
+ pure nothrow unittest {}
+
+ public unittest {}
+ extern(C) unittest {}
+ align unittest {}
+}
Something went wrong with that request. Please try again.