Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: define ‘operator<<’ for operands std::string and std::nullptr_t #2742

Merged
merged 1 commit into from Jul 10, 2022

Conversation

rodolforg
Copy link
Contributor

@rodolforg rodolforg commented Jul 9, 2022

fix for some compilers not accepting ASSERT_EQUAL(nullptr, something)

@ice0
Copy link
Collaborator

ice0 commented Jul 10, 2022

I suggest not to change the API here.
This looks like a more intuitive way to compare values.

This error can be fixed by adding overload for nullptr:

std::ostream& operator<<(std::ostream& os, std::nullptr_t) {
	return os << "nullptr";
}

P.S. Also it's still fails with error
Just saw your comment.

fix for some compilers not accepting ASSERT_EQUAL(nullptr, something)
@rodolforg rodolforg changed the title test: add ASSERT_NULL() to check if a pointer is nullptr test: define ‘operator<<’ for operands std::string and std::nullptr_t Jul 10, 2022
@rodolforg
Copy link
Contributor Author

This error can be fixed by adding overload for nullptr:

Got it. Done

@ice0 ice0 merged commit 1958902 into synfig:master Jul 10, 2022
@rodolforg rodolforg deleted the test-create-assert-null branch July 10, 2022 14:06
@rodolforg
Copy link
Contributor Author

Oh well, now I'm getting the error here on master branch o.O

@ice0
Copy link
Collaborator

ice0 commented Jul 10, 2022

Which one? Can you show log lines?

@rodolforg
Copy link
Contributor Author

make[2]: 'keyframe' está atualizado. 
  CXX      node.o
In file included from /home/rodolfo/projetos/synfig-puro/synfig-core/test/node.cpp:28:
/home/rodolfo/projetos/synfig-puro/synfig-core/test/node.cpp: In function ‘void find_node_returns_null_on_not_found()’:
/home/rodolfo/projetos/synfig-puro/synfig-core/test/test_base.h:64:33: error: ambiguous overload for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘std::nullptr_t’)
   64 |         oss << "\t - expected " << a << ", but got " << b << std::endl; \
/home/rodolfo/projetos/synfig-puro/synfig-core/test/test_base.h:85:17: note: in expansion of macro ‘ERROR_MESSAGE_TWO_VALUES’
   85 |                 ERROR_MESSAGE_TWO_VALUES(expected, value) \
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~
/home/rodolfo/projetos/synfig-puro/synfig-core/test/node.cpp:130:9: note: in expansion of macro ‘ASSERT_EQUAL’
  130 |         ASSERT_EQUAL(nullptr, find_node(GUID::zero()));
      |         ^~~~~~~~~~~~
In file included from /usr/include/c++/11/istream:39,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/glibmm-2.4/glibmm/ustring.h:26,
                 from /usr/include/glibmm-2.4/glibmm/exception.h:22,
                 from /usr/include/glibmm-2.4/glibmm/error.h:21,
                 from /usr/include/glibmm-2.4/glibmm/threads.h:31,
                 from /home/rodolfo/projetos/synfig-puro/synfig-core/src/synfig/node.h:42,
                 from /home/rodolfo/projetos/synfig-puro/synfig-core/test/node.cpp:26:
/usr/include/c++/11/ostream:108:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  108 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |       ^~~~~~~~
/usr/include/c++/11/ostream:117:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>; std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]’
  117 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |       ^~~~~~~~
/usr/include/c++/11/ostream:127:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  127 |       operator<<(ios_base& (*__pf) (ios_base&))
      |       ^~~~~~~~
/usr/include/c++/11/ostream:245:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  245 |       operator<<(const void* __p)
      |       ^~~~~~~~
/usr/include/c++/11/ostream:250:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::nullptr_t) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>; std::nullptr_t = std::nullptr_t]’
  250 |       operator<<(nullptr_t)
      |       ^~~~~~~~
In file included from /usr/include/c++/11/ostream:829,
                 from /usr/include/c++/11/istream:39,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/glibmm-2.4/glibmm/ustring.h:26,
                 from /usr/include/glibmm-2.4/glibmm/exception.h:22,
                 from /usr/include/glibmm-2.4/glibmm/error.h:21,
                 from /usr/include/glibmm-2.4/glibmm/threads.h:31,
                 from /home/rodolfo/projetos/synfig-puro/synfig-core/src/synfig/node.h:42,
                 from /home/rodolfo/projetos/synfig-puro/synfig-core/test/node.cpp:26:
/usr/include/c++/11/bits/ostream.tcc:119:5: note: candidate: ‘std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]’
  119 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/rodolfo/projetos/synfig-puro/synfig-core/test/node.cpp:28:
/home/rodolfo/projetos/synfig-puro/synfig-core/test/test_base.h:55:15: note: candidate: ‘std::ostream& operator<<(std::ostream&, std::nullptr_t)’
   55 | std::ostream& operator<<(std::ostream& os, std::nullptr_t)
      |               ^~~~~~~~
/home/rodolfo/projetos/synfig-puro/synfig-core/test/test_base.h:64:33: error: ambiguous overload for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘std::nullptr_t’)
   64 |         oss << "\t - expected " << a << ", but got " << b << std::endl; \
/home/rodolfo/projetos/synfig-puro/synfig-core/test/test_base.h:85:17: note: in expansion of macro ‘ERROR_MESSAGE_TWO_VALUES’
   85 |                 ERROR_MESSAGE_TWO_VALUES(expected, value) \
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~
/home/rodolfo/projetos/synfig-puro/synfig-core/test/node.cpp:134:9: note: in expansion of macro ‘ASSERT_EQUAL’
  134 |         ASSERT_EQUAL(nullptr, find_node(not_used_guid));
      |         ^~~~~~~~~~~~
In file included from /usr/include/c++/11/istream:39,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/glibmm-2.4/glibmm/ustring.h:26,
                 from /usr/include/glibmm-2.4/glibmm/exception.h:22,
                 from /usr/include/glibmm-2.4/glibmm/error.h:21,
                 from /usr/include/glibmm-2.4/glibmm/threads.h:31,
                 from /home/rodolfo/projetos/synfig-puro/synfig-core/src/synfig/node.h:42,
                 from /home/rodolfo/projetos/synfig-puro/synfig-core/test/node.cpp:26:
/usr/include/c++/11/ostream:108:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  108 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |       ^~~~~~~~
/usr/include/c++/11/ostream:117:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>; std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]’
  117 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |       ^~~~~~~~
/usr/include/c++/11/ostream:127:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  127 |       operator<<(ios_base& (*__pf) (ios_base&))
      |       ^~~~~~~~
/usr/include/c++/11/ostream:245:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  245 |       operator<<(const void* __p)
      |       ^~~~~~~~
/usr/include/c++/11/ostream:250:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::nullptr_t) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>; std::nullptr_t = std::nullptr_t]’
  250 |       operator<<(nullptr_t)
      |       ^~~~~~~~
In file included from /usr/include/c++/11/ostream:829,
                 from /usr/include/c++/11/istream:39,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/glibmm-2.4/glibmm/ustring.h:26,
                 from /usr/include/glibmm-2.4/glibmm/exception.h:22,
                 from /usr/include/glibmm-2.4/glibmm/error.h:21,
                 from /usr/include/glibmm-2.4/glibmm/threads.h:31,
                 from /home/rodolfo/projetos/synfig-puro/synfig-core/src/synfig/node.h:42,
                 from /home/rodolfo/projetos/synfig-puro/synfig-core/test/node.cpp:26:
/usr/include/c++/11/bits/ostream.tcc:119:5: note: candidate: ‘std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]’
  119 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/rodolfo/projetos/synfig-puro/synfig-core/test/node.cpp:28:
/home/rodolfo/projetos/synfig-puro/synfig-core/test/test_base.h:55:15: note: candidate: ‘std::ostream& operator<<(std::ostream&, std::nullptr_t)’
   55 | std::ostream& operator<<(std::ostream& os, std::nullptr_t)
      |               ^~~~~~~~
make[2]: *** [Makefile:740: node.o] Erro 1

@ice0
Copy link
Collaborator

ice0 commented Jul 10, 2022

Which OS/compiler version you are using?

@rodolforg
Copy link
Contributor Author

$ uname -a
Linux [hostname] 5.18.0-2-amd64 #1 SMP PREEMPT_DYNAMIC Debian 5.18.5-1 (2022-06-16) x86_64 GNU/Linux

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 11.3.0-3' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-6lTGZp/gcc-11-11.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-6lTGZp/gcc-11-11.3.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.0 (Debian 11.3.0-3) 

@ice0
Copy link
Collaborator

ice0 commented Jul 11, 2022

Should be fixed by #2744

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants