[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-dev
Subject:    Re: [cfe-dev] libc++: Unexpected pointer-to-member-function behavior
From:       David Blaikie via cfe-dev <cfe-dev () lists ! llvm ! org>
Date:       2017-04-21 15:54:13
Message-ID: CAENS6EtFOuqu9pS-Gtxi44=CL8a=r9ctj22=yPA7xVmxwAS0kg () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


FWIW the C++ standard doesn't allow taking the address of standard library
member functions (I don't know the wording - but I can go hunt for it), so
far as I understand.

That said, interesting failure - not what I'd have expected.

On Thu, Apr 20, 2017 at 10:45 PM Adam C. Emerson via cfe-dev <
cfe-dev@lists.llvm.org> wrote:

> Hello. I'm not sure if this is a bug or if I'm using undefined
> behavior or otherwise doing something screwy.
>
> My Minimal Working Reproducer is:
>
> ---------->8-----------
>
> #include <functional>
> #include <iostream>
> #include <string>
>
> int main(void) {
>     auto s = ::std::string("Meow.");
>     auto l = ::std::mem_fn(&::std::string::size);
>
>     ::std::cout << l(s) << ::std::endl;
>
>     return 0;
> }
>
> ---------->8-----------
>
> If I compile this under g++ or with clang++ using libstdc++, this
> compiles and works as expected. However, if I use clang++ (v4.0.0 on
> Arch Linux x86_64) with libc++ (4.0.0), I get a link error:
>
> ---------->8-----------
>
> % clang++ -v -std=c++14 -stdlib=libc++ foo.cc
> clang version 4.0.0 (tags/RELEASE_400/final)
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /usr/bin
> Found candidate GCC installation:
> /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.1
> Found candidate GCC installation:
> /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1
> Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1
> Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/6.3.1
> Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1
> Candidate multilib: .;@m64
> Candidate multilib: 32;@m32
> Selected multilib: .;@m64
>  "/usr/bin/clang-4.0" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj
> -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names
> -main-file-name foo.cc -mrelocation-model static -mthread-model posix
> -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases
> -munwind-tables -fuse-init-array -target-cpu x86-64 -v -dwarf-column-info
> -debugger-tuning=gdb -resource-dir /usr/bin/../lib/clang/4.0.0
> -internal-isystem /usr/bin/../include/c++/v1 -internal-isystem
> /usr/local/include -internal-isystem /usr/bin/../lib/clang/4.0.0/include
> -internal-externc-isystem /include -internal-externc-isystem /usr/include
> -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /home/azure
> -ferror-limit 19 -fmessage-length 119 -fobjc-runtime=gcc -fcxx-exceptions
> -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o
> /tmp/foo-1fe78b.o -x c++ foo.cc
> clang -cc1 version 4.0.0 based upon LLVM 4.0.0 default target
> x86_64-unknown-linux-gnu
> ignoring nonexistent directory "/include"
> #include "..." search starts here:
> #include <...> search starts here:
>  /usr/bin/../include/c++/v1
>  /usr/local/include
>  /usr/bin/../lib/clang/4.0.0/include
>  /usr/include
> End of search list.
>  "/usr/bin/ld" --eh-frame-hdr -m elf_x86_64 -dynamic-linker
> /lib64/ld-linux-x86-64.so.2 -o a.out
> /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib64/crt1.o
> /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib64/crti.o
> /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/crtbegin.o
> -L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1
> -L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib64
> -L/usr/bin/../lib64 -L/lib/../lib64 -L/usr/lib/../lib64
> -L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../..
> -L/usr/bin/../lib -L/lib -L/usr/lib /tmp/foo-1fe78b.o -lc++ -lm -lgcc_s
> -lgcc -lc -lgcc_s -lgcc
> /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/crtend.o
> /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib64/crtn.o
> /tmp/foo-1fe78b.o: In function `main':
> foo.cc:(.text+0x44d): undefined reference to `std::__1::basic_string<char,
> std::__1::char_traits<char>, std::__1::allocator<char> >::size() const'
> /usr/bin/ld: a.out: hidden symbol
> `_ZNKSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE4sizeEv'
> isn't defined
> /usr/bin/ld: final link failed: Bad value
> clang-4.0: error: linker command failed with exit code 1 (use -v to see
> invocation)
>
> ---------->8-----------
>
> Thank you very much.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>

[Attachment #5 (text/html)]

<div dir="ltr">FWIW the C++ standard doesn&#39;t allow taking the address of standard \
library member functions (I don&#39;t know the wording - but I can go hunt for it), \
so far as I understand.<br><br>That said, interesting failure - not what I&#39;d have \
expected.</div><br><div class="gmail_quote"><div dir="ltr">On Thu, Apr 20, 2017 at \
10:45 PM Adam C. Emerson via cfe-dev &lt;<a \
href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex">Hello. I&#39;m not sure if this is \
a bug or if I&#39;m using undefined<br> behavior or otherwise doing something \
screwy.<br> <br>
My Minimal Working Reproducer is:<br>
<br>
----------&gt;8-----------<br>
<br>
#include &lt;functional&gt;<br>
#include &lt;iostream&gt;<br>
#include &lt;string&gt;<br>
<br>
int main(void) {<br>
      auto s = ::std::string(&quot;Meow.&quot;);<br>
      auto l = ::std::mem_fn(&amp;::std::string::size);<br>
<br>
      ::std::cout &lt;&lt; l(s) &lt;&lt; ::std::endl;<br>
<br>
      return 0;<br>
}<br>
<br>
----------&gt;8-----------<br>
<br>
If I compile this under g++ or with clang++ using libstdc++, this<br>
compiles and works as expected. However, if I use clang++ (v4.0.0 on<br>
Arch Linux x86_64) with libc++ (4.0.0), I get a link error:<br>
<br>
----------&gt;8-----------<br>
<br>
% clang++ -v -std=c++14 -stdlib=libc++ foo.cc<br>
clang version 4.0.0 (tags/RELEASE_400/final)<br>
Target: x86_64-unknown-linux-gnu<br>
Thread model: posix<br>
InstalledDir: /usr/bin<br>
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.1<br>
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1<br>
Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1<br>
Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/6.3.1<br>
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1<br>
Candidate multilib: .;@m64<br>
Candidate multilib: 32;@m32<br>
Selected multilib: .;@m64<br>
  &quot;/usr/bin/clang-4.0&quot; -cc1 -triple x86_64-unknown-linux-gnu -emit-obj \
-mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name \
foo.cc -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno \
-masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu \
x86-64 -v -dwarf-column-info -debugger-tuning=gdb -resource-dir \
/usr/bin/../lib/clang/4.0.0 -internal-isystem /usr/bin/../include/c++/v1 \
-internal-isystem /usr/local/include -internal-isystem \
/usr/bin/../lib/clang/4.0.0/include -internal-externc-isystem /include \
-internal-externc-isystem /usr/include -std=c++14 -fdeprecated-macro \
-fdebug-compilation-dir /home/azure -ferror-limit 19 -fmessage-length 119 \
-fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option \
-fcolor-diagnostics -o /tmp/foo-1fe78b.o -x c++ foo.cc<br> clang -cc1 version 4.0.0 \
based upon LLVM 4.0.0 default target x86_64-unknown-linux-gnu<br> ignoring \
nonexistent directory &quot;/include&quot;<br> #include &quot;...&quot; search starts \
here:<br> #include &lt;...&gt; search starts here:<br>
  /usr/bin/../include/c++/v1<br>
  /usr/local/include<br>
  /usr/bin/../lib/clang/4.0.0/include<br>
  /usr/include<br>
End of search list.<br>
  &quot;/usr/bin/ld&quot; --eh-frame-hdr -m elf_x86_64 -dynamic-linker \
/lib64/ld-linux-x86-64.so.2 -o a.out \
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib64/crt1.o \
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib64/crti.o \
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/crtbegin.o \
-L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1 \
-L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib64 \
-L/usr/bin/../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 \
-L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../.. -L/usr/bin/../lib -L/lib \
-L/usr/lib /tmp/foo-1fe78b.o -lc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc \
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/crtend.o \
                /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib64/crtn.o<br>
                
/tmp/foo-1fe78b.o: In function `main&#39;:<br>
foo.cc:(.text+0x44d): undefined reference to `std::__1::basic_string&lt;char, \
std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;::size() \
                const&#39;<br>
/usr/bin/ld: a.out: hidden symbol \
`_ZNKSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE4sizeEv&#39; \
                isn&#39;t defined<br>
/usr/bin/ld: final link failed: Bad value<br>
clang-4.0: error: linker command failed with exit code 1 (use -v to see \
invocation)<br> <br>
----------&gt;8-----------<br>
<br>
Thank you very much.<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" \
target="_blank">cfe-dev@lists.llvm.org</a><br> <a \
href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" \
target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br> \
</blockquote></div>


[Attachment #6 (text/plain)]

_______________________________________________
cfe-dev mailing list
cfe-dev@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic