Summary: pragma(msg,...) has bugs + alternative idea
           Product: D
           Version: 2.041
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from 2010-03-13 05:11:28 PST ---
The D2 docs state about pragma(msg, ...):
Prints a message while compiling, the AssignExpressions must be string
pragma(msg, "compiling...");

I think that means it must accept string literals only, and produce a syntax
error in all the other cases. In practice if you look at the following program
the pragma(msg, foo0()); prints the "this is a test" string. This is useful,
but in many other cases this doesn't work or works in strange ways:

string foo0() {
    return "this is a test";
string foo1() {
    return "";
string foo2() {
    string result;
    return result;
string foo3() {
    return [];
pragma(msg, foo0());
pragma(msg, foo1());
pragma(msg, foo2());
pragma(msg, foo3());
string hello = "red";
pragma(msg, hello);
pragma(msg, 12);
void main() {}

The compile-timeoutput of that program is:
this is a test


So I think pragma(msg,...) needs some debugging.


This program doesn't compile:

enum int x = 10;
static if (x)
    pragma(msg, "true");
    pragma(msg, "false");
void main() {}

It prints the error:
test.d(4): Declaration expected, not 'else'

I can understand the cause of that error, but to improve the usefulness of the
pragma and avoid errors like that one I think the compiler can rewrite the
pragma(msg, ...) as:

{pragma(msg, ...);}


To increase the usefulness of the pragma(msg, ...) I suggest to not let it
print a newline after the string.


D2 programs have a better and better CTFE, so the need for good enough printing
is growing.

So I suggest to add a simple printing function that works in the same way both
at compile-time in CTFE and at runtime. To keep things simple it can just print
a string (literal or inside a variable) and it does NOT print a newline.

It can be used in a loop too, in CTFE too, to print many things (so it's
different from a pragma(msg,...):

string foo(int i) {
    foreach (i, 0 .. 10)

Note that it's a true function, so there is no need for {}.

"ctputs" is just one of the possible names of this function.

Once such function is present, the pragma(msg,...) can probably be removed from
the language.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to