EnteringContext approach to nested-name-specifiers interacts badly with pointers-to-members
| Bugzilla Link | 15554 |
| Version | trunk |
| OS | All |
| Attachments | unreduced test case, preprocessed |
| Reporter | LLVM Bugzilla Contributor |
| CC | @DougGregor,@zygoloid |
Extended Description
Seen assertion failure in C++ front-end. This is is running my powerpc-darwin8 branch, but probably affects all.
% /Users/fang/local/src/LLVM-svn/gcc40-cmake-build/bin/clang++ -DHAVE_CONFIG_H -I. -I../../bj-jedi-git/src -I/sw/include -O0 -MT bj/core/strategy.lo -MD -MP -MF bj/core/.deps/strategy.Tpo -c ../../bj-jedi-git/src/bj/core/strategy.cc -fno-common -DPIC -o bj/core/.libs/strategy.o -save-temps /Users/fang/local/src/LLVM-svn/llvm/tools/clang/lib/Sema/SemaTemplateDeduction.cpp:350: failed assertion `(Value->isTypeDependent() || Value->isValueDependent()) && "Expression template argument must be type- or value-dependent."' Stack dump: 0. Program arguments: /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang-3.1 -cc1 -triple powerpc-apple-macosx10.4.0 -S -disable-free -main-file-name strategy.cc -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -coverage-file /Users/fang/local/src/bj-jedi/clang-build/src/strategy.s -resource-dir /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.3 -O0 -fdeprecated-macro -fdebug-compilation-dir /Users/fang/local/src/bj-jedi/clang-build/src -ferror-limit 19 -fmessage-length 80 -mstackrealign -fblocks -fblocks-runtime-optional -fobjc-runtime=macosx-10.4.0 -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fno-common -fdiagnostics-show-option -fcolor-diagnostics -backend-option -vectorize-loops -o strategy.s -x c++-cpp-output strategy.ii
-
<eof> parser at end of file -
/usr/include/c++/4.0.0/bits/stl_algobase.h:375:5: instantiating function definition 'copy' -
/usr/include/c++/4.0.0/bits/stl_algobase.h:325:9: instantiating function definition 'copy_n' -
/usr/include/c++/4.0.0/bits/stl_algobase.h:307:5: instantiating function definition '__copy_aux' -
/usr/include/c++/4.0.0/bits/stl_algobase.h:280:9: instantiating function definition 'copy'
clang-3.1: error: unable to execute command: Abort trap clang-3.1: error: clang frontend command failed due to signal (use -v to see invocation) clang version 3.3 Target: powerpc-apple-darwin8.11.0 Thread model: posix clang-3.1: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script. clang-3.1: note: diagnostic msg:
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang-3.1: note: diagnostic msg: /tmp/strategy-B63fyA.cpp clang-3.1: note: diagnostic msg: /tmp/strategy-B63fyA.sh clang-3.1: note: diagnostic msg:
Will post a compressed-but-unreduced test case shortly.
This is still broken: the testcase in comment#10 is still incorrectly rejected.
This seems to work on r192115! (tested on powerpc-darwin8) What revision fixed this, out of curiosity? (and was a test case added?)
Ping? My reduced test case still fails in the same way, at r186828.
Ping. Still fails on trunk. Any chance of this getting fixed in time for release 3.3?
Much nastier case:
template<typename T> struct A;
template<typename T> struct A<T*> { static float A<T>::X::*p; };
template<typename T> float A<T>::X::*(A<T*>::p);
Here, we can't tell whether we're EnteringContext until after we've looked past the nested-name-specifier and seen that it's declaring a pointer-to-member. Perhaps when we are EnteringContext and we see a name component following a dependent-looking NNS, we could perform a tentative parse to see if there's a * after the NNS, or keep all subsequent name components as identifiers, and use RebuildNestedNameSpecifierInCurrentInstantiation to fix up afterwards.
If anyone cares, g++ 4.0.1, 4.4.7, 4.5.3, 4.6.3, 4.7.2 all compile these test cases fine.
We have a rejects-valid on this, which is probably the same issue:
template<typename T> struct iterator_traits;
template <typename T> void f() {
float iterator_traits<T>::value_type::*p = 0;
}
<stdin>:4:29: error: no member named 'value_type' in 'iterator_traits<T>'
float iterator_traits<T>::value_type::*p = 0;
~~~~~~~~~~~~~~~~~~~~^
We're probably performing a lookup into the dependent nested name specifier because we're parsing with EnteringContext = true.
error: /Users/fang/local/src/LLVM-svn/llvm/tools/clang/lib/Sema/SemaTemplateDeduction.cpp:350: failed assertion `(Value->isTypeDependent() || Value->isValueDependent()) && "Expression template argument must be type- or value-dependent."' Stack dump: 0. Program arguments: /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang-3.1 -cc1 -triple powerpc-apple-macosx10.4.0 -emit-obj -mrelax-all -disable-free -main-file-name strategy.ii -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -coverage-file /Users/fang/temp/clang/delta2/strategy.o -resource-dir /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.3 -fdeprecated-macro -fdebug-compilation-dir /Users/fang/temp/clang/delta2 -ferror-limit 1 -fmessage-length 0 -mstackrealign -fblocks -fblocks-runtime-optional -fobjc-runtime=macosx-10.4.0 -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -backend-option -vectorize-loops -o strategy.o -x c++-cpp-output strategy.ii
-
strategy.ii:23:14: current parser token ')' -
strategy.ii:21:16: parsing function body 'main' -
strategy.ii:21:16: in compound statement ('{}')
updated delta script: builddir=/Volumes/Isolde/sources/LLVM-svn/gcc40-cmake-build cxxflags="-ferror-limit=1"
make sure is valid C++
g++ -Wall -W -Werror -c strategy.ii -o strategy.o 2> /dev/null
$builddir/bin/clang++ $cxxflags -o strategy.o -c strategy.ii 2>&1
| grep -q "failed assertion.*Expression template argument must be type- or value-dependent"
more-reduced, still-valid:
template
typedef typename _It::value_type value_type;
};
template
typedef _Tp value_type;
};
struct RS { float edge; };
template <typename _It, float iterator_traits<_It>::value_type::*> struct MSIter { typedef float value_type; MSIter(const _It); };
template <typename _It, float RS::*mem> int foo(const MSIter<_It, mem>&) { return 0; }
int main(void) { typedef MSIter<const RS*, &RS::edge> c_iter; const c_iter i(0); return foo(i); }
more reduced and valid test case:
typedef long int ptrdiff_t;
template
typedef _Tp value_type;
};
template
template
template <typename _It, typename T, T iterator_traits<_It>::value_type::*mem>
struct MSIter : public iterator
template <typename _It, typename T, T iterator_traits<_It>::value_type::*mem> inline ptrdiff_t operator - (const MSIter<_It,T,mem>&, const MSIter<_It,T,mem>&) { return 0; }
int main(void) {
typedef array
valid C++ test case this test case is valid C++, semi-reduced
This was using r176996 on svn-trunk/git-master, which was merged into the powerpc-darwin8 branch.
I have delta crunching away at reducing this, but on a rather slow machine, so it may take several days...
delta script:
#!/bin/sh -e
builddir=/Volumes/Isolde/sources/LLVM-svn/gcc40-cmake-build
$builddir/bin/clang++ -fno-common -O0 -DPIC -o strategy.o -c strategy.ii 2>&1
| grep -q "failed assertion.*Expression template argument must be type- or value-dependent"
Reduced test case by the author appears to be fixed in Clang 3.4: https://godbolt.org/z/P5Tzj1ra9 The first test case by Richard appears to be fixed in Clang 3.4 as well: https://godbolt.org/z/oGnKohGar The second test case by Richard is still rejected by every implementation except for GCC: https://godbolt.org/z/aerEhjs97
@llvm/issue-subscribers-clang-frontend
The second test case by Richard is still rejected by every implementation except for GCC: https://godbolt.org/z/aerEhjs97
Clang trunk can now compile this code. CC @Endilll
Fixed in both clang and gcc trunk: https://godbolt.org/z/4MoYxe1cr
although edg/MSVC still don't accept.
Do we have tests for all these cases? This seems like the sort of thing that could easily regress.