Clang/C++ problem?

Shouldn't this work?
If it should work, should I write up a bug?

$ cat junk.cpp

typedef int Foo_t;

template <typename T>
T DoSomething ( T t) { return t; }

int main ( int argc, char *argv ) {
    int foo = 23;
    DoSomething ( static_cast<unsigned int>(foo));
    DoSomething ( static_cast<unsigned Foo_t>(foo));
    return 0;
    }

$ g++ junk.cpp

$ clang junk.cpp

junk.cpp:9:36: error: expected '>'
        DoSomething ( static_cast<unsigned Foo_t>(foo));
                                          ^
                                          >
junk.cpp:9:27: note: to match this '<'
        DoSomething ( static_cast<unsigned Foo_t>(foo));
                                 ^
1 error generated.

Marshall Clow Idio Software <mailto:mclow.lists@gmail.com>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki

AMDG

Shouldn't this work?

My gut feel reaction is that it shouldn't,
but I haven't actually checked the standard.

If it should work, should I write up a bug?

$ cat junk.cpp

typedef int Foo_t;

template<typename T>
T DoSomething ( T t) { return t; }

int main ( int argc, char *argv ) {
     int foo = 23;
     DoSomething ( static_cast<unsigned int>(foo));
     DoSomething ( static_cast<unsigned Foo_t>(foo));
     return 0;
     }

What about something simpler?
Does

typedef int Foo_t;
typedef unsigned Foo_t uFoo_t;

work?

$ g++ junk.cpp

$ clang junk.cpp

junk.cpp:9:36: error: expected '>'
         DoSomething ( static_cast<unsigned Foo_t>(foo));
                                           ^
                                           >
junk.cpp:9:27: note: to match this '<'
         DoSomething ( static_cast<unsigned Foo_t>(foo));
                                  ^
1 error generated.

In Christ,
Steven Watanabe

No it does not - but gcc doesn't accept it either.
$ g++ junk.cpp
junk.cpp:2: error: invalid combination of multiple type-specifiers

On the other hand, clang doesn't like this (and gcc thinks that it's fine)
  DoSomething ((unsigned Foo_t)(foo));

I've opened bug #9040, but I'm still updating it.

Marshall Clow Idio Software <mailto:mclow.lists@gmail.com>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki

AMDG

Marshall Clow wrote:

Shouldn't this work?
If it should work, should I write up a bug?

$ cat junk.cpp

typedef int Foo_t;

template <typename T>
T DoSomething ( T t) { return t; }

int main ( int argc, char *argv ) {
    int foo = 23;
    DoSomething ( static_cast<unsigned int>(foo));
    DoSomething ( static_cast<unsigned Foo_t>(foo));
    return 0;
    }

$ g++ junk.cpp

$ clang junk.cpp

junk.cpp:9:36: error: expected '>'
        DoSomething ( static_cast<unsigned Foo_t>(foo));
                                          ^
                                          >
junk.cpp:9:27: note: to match this '<'
        DoSomething ( static_cast<unsigned Foo_t>(foo));
                                 ^
1 error generated.

No, this shouldn't work. Some types, like 'unsigned int' are formed by two keywords, but that doesn't mean you can use one keyword first and add the other one later.

Bo Persson

Thanks Steven and Bo.
I've closed the bug as "invalid".

However, if there's a "gcc compatibility" document somewhere, this should probably go into it.
(Since gcc accepts this code w/o complaint - even at -Wall)

-- Marshall

Marshall Clow Idio Software <mailto:mclow.lists@gmail.com>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki

The online version of Comeau C++ 4.3.10.1 produced the same errors:

"ComeauTest.c", line 12: error: expected a ">"
      DoSomething ( static_cast<unsigned Foo_t>(foo));
                                         ^

Csaba

No, it should not work, because (i think) it is similar with the code as follows,


unsigned int int var = 0;


your problem is that you treat the typedef as macro here, so you think when processing unsigned Foo_t, it should be treated as unsigned int.


But, again, it’s not macro.

11年1月25日,周二, Marshall Clow mclow.lists@gmail.com 写道:


> 发件人: Marshall Clow mclow.lists@gmail.com
> 主题: [cfe-dev] Clang/C++ problem?
> 收件人: “CLang-list” cfe-dev@cs.uiuc.edu
> 日期: 2011年1月25日,周二,上午5:08
>
> Shouldn’t this work?
> If it should work, should I write up a bug?
>
> $ cat junk.cpp
> > typedef int Foo_t;
> >
> > template
> > T DoSomething ( T t) { return t; }
> >
> > int main ( int argc, char *argv ) {
> > int foo = 23;
> > DoSomething ( static_cast(foo));
> > DoSomething ( static_cast(foo));
> > return 0;
> > }
> >
>
> $ g++ junk.cpp
>
> $ clang junk.cpp
> > junk.cpp:9:36: error: expected ‘>’
> > DoSomething ( static_cast(foo));
> > ^
> > >
> > junk.cpp:9:27: note: to match this ‘<’
> > DoSomething ( static_cast(foo));
> > ^
> > 1 error generated.
> >
>
> Marshall Clow Idio Software mailto:mclow.lists@gmail.com
>
> A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
> – Yu Suzuki
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev@cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


|