Bug 40114 - Incomplete flow analysis in template produces spurious diagnostic
Summary: Incomplete flow analysis in template produces spurious diagnostic
Status: RESOLVED DUPLICATE of bug 4210
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.3
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-12 11:13 UTC by Gareth Owen
Modified: 2009-05-12 14:49 UTC (History)
8 users (show)

See Also:
Host: Win32
Target: mingw32
Build: 4.3.3-tdm-1 mingw32
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gareth Owen 2009-05-12 11:13:02 UTC
Using built-in specs.
Target: mingw32
Configured with: ../gcc-4.3.3/configure --prefix=/mingw --build=mingw32 --enable-languages=c,ada,c++,fortran,objc,obj-c++ --with-bugurl=http://www.tdragon.net/recentgcc/bugs.php --disable-nls --disable-win32-registry --enable-libgomp --disable-werror --enable-threads --disable-symvers --enable-cxx-flags='-fno-function-sections -fno-data-sections' --enable-fully-dynamic-string --enable-version-specific-runtime-libs --enable-sjlj-exceptions --with-pkgversion='4.3.3-tdm-1 mingw32'
Thread model: win32
gcc version 4.3.3 (4.3.3-tdm-1 mingw32)


The following code produces an incorrect diagnostic 
"warning: left shift count >= width of type"

template <unsigned M, unsigned N>
unsigned frob(unsigned q)
{
  if(M > N)
    return (q << (M-N));
  else
    return (q << (N-M));
}

int main()
{
  return frob<3,2> (7U);
}

This happens at -O0 and -O3, with default warnings.
Since I compile with -Werror, this is a minor pain (although it can be worked around easily). Since M and N are template parameters, is it possible for flow analysis to deduce that this is can not actually happen?
(The code on which this is based comes from a routine converting between fixed point numbers with different radix position).
Comment 1 Andrew Pinski 2009-05-12 14:49:49 UTC

*** This bug has been marked as a duplicate of 4210 ***