public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ - compilation error for all implicit conversion
@ 2018-03-05  7:42 Satya Prakash Prasad
  2018-03-05  8:08 ` Liu Hao
  0 siblings, 1 reply; 5+ messages in thread
From: Satya Prakash Prasad @ 2018-03-05  7:42 UTC (permalink / raw)
  To: gcc

Is there a compiler flag that logs warning / error in case of any implicit
conversions - like int32_t to uint32_t.

#include <cstdint>
#include <iostream>

using ::std::int32_t;
using ::std::uint32_t;

int main(int argc, char *argv[])
{
   int32_t x = 9;
    uint32_t i = x;
   uint32_t i1 = socketread(...); // returns  int32_t  -1 on error and >0
on success
    std::cout << " " << x << " " << i << std::flush << std::endl;
    return 0;
}
c++ -std=c++11 -Wall -Wconversion -Wpedantic cast.cpp

I get no issues / warning / error during compilation - is there a way it
can achieved.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C++ - compilation error for all implicit conversion
  2018-03-05  7:42 C++ - compilation error for all implicit conversion Satya Prakash Prasad
@ 2018-03-05  8:08 ` Liu Hao
  2018-03-05  8:17   ` Satya Prakash Prasad
  0 siblings, 1 reply; 5+ messages in thread
From: Liu Hao @ 2018-03-05  8:08 UTC (permalink / raw)
  To: Satya Prakash Prasad, gcc

在 2018年03月05日 15:42, Satya Prakash Prasad 写道:
> Is there a compiler flag that logs warning / error in case of any implicit
> conversions - like int32_t to uint32_t.
> 
> #include <cstdint>
> #include <iostream>
> 
> using ::std::int32_t;
> using ::std::uint32_t;
> 
> int main(int argc, char *argv[])
> {
>    int32_t x = 9;
>     uint32_t i = x;
>    uint32_t i1 = socketread(...); // returns  int32_t  -1 on error and >0
> on success
>     std::cout << " " << x << " " << i << std::flush << std::endl;
>     return 0;
> }
> c++ -std=c++11 -Wall -Wconversion -Wpedantic cast.cpp
> 
> I get no issues / warning / error during compilation - is there a way it
> can achieved.
> 

Try `-Wsign-conversion` in addition to `-Wconversion`.


-- 
Best regards,
LH_Mouse

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C++ - compilation error for all implicit conversion
  2018-03-05  8:08 ` Liu Hao
@ 2018-03-05  8:17   ` Satya Prakash Prasad
  2018-03-05  8:30     ` Liu Hao
  0 siblings, 1 reply; 5+ messages in thread
From: Satya Prakash Prasad @ 2018-03-05  8:17 UTC (permalink / raw)
  To: Liu Hao; +Cc: gcc

I still does not throws an error:

#include <cstdint>

#include <iostream>

using ::std::int32_t;

using ::std::uint32_t;

int32_t callme()

{

int32_t x = -1;

return x;

}

int main()

{

int32_t x = 9;

uint32_t i = x;

uint32_t i1 = callme();

std::cout << " " << x << " " << i << " " << i1 << std::flush << std::endl;

return 0;

}


/c/tools/mingw64/bin/c++ -std=c++11 -Wall -Wconversion -Wpedantic -Wextra
-w -Wsign-compare -Wnarrowing -Wreturn-type -Wno-int-conversion
-Wtype-limits -Wuseless-cast -Wsign-conversion -Wextra -Wsign-conversion
cast.cpp




On Mon, Mar 5, 2018 at 1:38 PM, Liu Hao <lh_mouse@126.com> wrote:

> 在 2018年03月05日 15:42, Satya Prakash Prasad 写道:
> > Is there a compiler flag that logs warning / error in case of any
> implicit
> > conversions - like int32_t to uint32_t.
> >
> > #include <cstdint>
> > #include <iostream>
> >
> > using ::std::int32_t;
> > using ::std::uint32_t;
> >
> > int main(int argc, char *argv[])
> > {
> >    int32_t x = 9;
> >     uint32_t i = x;
> >    uint32_t i1 = socketread(...); // returns  int32_t  -1 on error and >0
> > on success
> >     std::cout << " " << x << " " << i << std::flush << std::endl;
> >     return 0;
> > }
> > c++ -std=c++11 -Wall -Wconversion -Wpedantic cast.cpp
> >
> > I get no issues / warning / error during compilation - is there a way it
> > can achieved.
> >
>
> Try `-Wsign-conversion` in addition to `-Wconversion`.
>
>
> --
> Best regards,
> LH_Mouse
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C++ - compilation error for all implicit conversion
  2018-03-05  8:17   ` Satya Prakash Prasad
@ 2018-03-05  8:30     ` Liu Hao
  2018-03-05  8:34       ` Satya Prakash Prasad
  0 siblings, 1 reply; 5+ messages in thread
From: Liu Hao @ 2018-03-05  8:30 UTC (permalink / raw)
  To: Satya Prakash Prasad; +Cc: gcc

在 2018年03月05日 16:17, Satya Prakash Prasad 写道:
> I still does not throws an error:
> (... abridged ...)
> 
> /c/tools/mingw64/bin/c++ -std=c++11 -Wall -Wconversion -Wpedantic
> -Wextra -w -Wsign-compare -Wnarrowing -Wreturn-type -Wno-int-conversion
> -Wtype-limits -Wuseless-cast -Wsign-conversion -Wextra -Wsign-conversion
> cast.cpp
> 
> 

Your `-w` option suppressed all warnings.


-- 
Best regards,
LH_Mouse

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: C++ - compilation error for all implicit conversion
  2018-03-05  8:30     ` Liu Hao
@ 2018-03-05  8:34       ` Satya Prakash Prasad
  0 siblings, 0 replies; 5+ messages in thread
From: Satya Prakash Prasad @ 2018-03-05  8:34 UTC (permalink / raw)
  To: Liu Hao; +Cc: gcc

Thanks a lot - I just picked up all compiler flags that we make use in our
project.

Thanks a lot for the information as provided.

Regards,
Prakash

On Mon, Mar 5, 2018 at 2:00 PM, Liu Hao <lh_mouse@126.com> wrote:

> 在 2018年03月05日 16:17, Satya Prakash Prasad 写道:
> > I still does not throws an error:
> > (... abridged ...)
> >
> > /c/tools/mingw64/bin/c++ -std=c++11 -Wall -Wconversion -Wpedantic
> > -Wextra -w -Wsign-compare -Wnarrowing -Wreturn-type -Wno-int-conversion
> > -Wtype-limits -Wuseless-cast -Wsign-conversion -Wextra -Wsign-conversion
> > cast.cpp
> >
> >
>
> Your `-w` option suppressed all warnings.
>
>
> --
> Best regards,
> LH_Mouse
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-03-05  8:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-05  7:42 C++ - compilation error for all implicit conversion Satya Prakash Prasad
2018-03-05  8:08 ` Liu Hao
2018-03-05  8:17   ` Satya Prakash Prasad
2018-03-05  8:30     ` Liu Hao
2018-03-05  8:34       ` Satya Prakash Prasad

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).