title: Comparison of unsigned int is always true (npos issue?)
body: <p>I’m receiving an error:</p>
  
  <pre>
  error: comparison of constant 18446744073709551614 with
       expression of type 'unsigned int' is always true
       [-Werror,-Wtautological-constant-out-of-range-compare]
  </pre>
  
  <p>The line of code it is referring to is this:</p>
  
  <pre><code>if (key_index != std::string::npos)
  </code></pre>
  
  <p><code>key_index</code> is an <code>unsigned int</code> local variable in my <code>main()</code> function that my <code>if</code> statement is also in.</p>
  
  <p>I read through a few posts on here already, trying to make sense of where I’m going wrong.</p>
  
  <p>This link was the most informative</p>
  
  <p><a href="https://stackoverflow.com/questions/3827926/">What does string::npos mean</a></p>
  
  <p>But, even utilizing the advice from there, I’m still coming up with the same errors.</p>
  
  <p>I’ve tried to create my own variable:</p>
  
  <pre><code>const int NPOS = -1
  </code></pre>
  
  <p>I’ve modified the comparison operator a few different ways.</p>
  
  <p>I’ve tried turning the line into:</p>
  
  <pre><code>if(key_index != (std::string::npos -1))
  </code></pre>
  
  <p>I’ve tried a few other minor changes, which I cannot recall at the moment.</p>
  
  <p>I forgot to write them down, and I apologize for not having all of my test/mod details.</p>
  
  <p>This is the full <code>main()</code> code the issue is coming from. For all I know, there might be something else that I need to correct instead.</p>
  
  <pre><code>#include &lt;SFML/Graphics.hpp&gt;
  #include &lt;SFML/System.hpp&gt;
  #include &lt;SFML/Audio.hpp&gt;
  #include &lt;SFML/Window.hpp&gt;
  #include &lt;math.h&gt;  // For pow()
  #include &lt;string&gt;
  #include &lt;stdexcept&gt;  // For std::runtime_error
  #include &lt;vector&gt;
  #include "GuitarString.hpp"
  
  const sf::Uint32 quit_key = 27;       // ASCII 27 is the Escape key
  
  const std::string keyboard = "q2we4r5ty7u8i9op-[=zxdcfvgbnjmk,.;/' ";
  const int num_keys = keyboard.length();
  const int kDuration = 8;
  
  std::vector&lt;sf::Int16&gt; makeSamplesFromString(GuitarString *gs) {
      std::vector&lt;sf::Int16&gt; samples;
  
      gs-&gt;pluck();
      for (int i= 0; i &lt; kSampleRate * kDuration; i++) {
          gs-&gt;tic();
          samples.push_back(gs-&gt;sample());
      }
  
      return samples;
  }
  
  int main() {
      sf::Event event;
      double frequency;    
      unsigned int key_index; 
  
      std::vector &lt; std::vector&lt;sf::Int16&gt; &gt; samples(num_keys);
  
      std::vector&lt;sf::SoundBuffer&gt; buffers(num_keys);
  
      std::vector&lt;sf::Sound&gt; sounds(num_keys);
  
      for (int i = 0; i &lt; num_keys; ++i) {
          frequency = 440 * pow(2, (i-24) / 12.0L);
          GuitarString gs = GuitarString(frequency);
  
          samples[i] = makeSamplesFromString(&amp;gs);
  
          if (!buffers[i].loadFromSamples(&amp;samples[i][0],
                                      samples[i].size(), 2, kSampleRate)) {
              throw std::runtime_error("sf::SoundBuffer: failed to load from samples.");
          }
  
          sounds[i].setBuffer(buffers[i]);
      }
  
      sf::Vector2u size_win(500, 200);
      sf::Sprite background_sprite;       
      sf::Texture background_texture;
      if (background_texture.loadFromFile("keyboard.png")) {
          background_sprite.setTexture(background_texture);
          size_win = background_texture.getSize();
      }
  
      sf::RenderWindow window(sf::VideoMode(size_win.x, size_win.y),
                            " PS5B GuitarHero - Press Escape to Exit ");
  
      window.setKeyRepeatEnabled(false);
  
      while (window.isOpen()) {
          while (window.pollEvent(event)) {
              switch (event.type) {
                  case sf::Event::Closed:
                      window.close();
                      break;
                  case sf::Event::TextEntered:
                      key_index = keyboard.find(event.text.unicode);
                      if (key_index != std::string::npos) { // the line causing the issue….
                          sounds[key_index].play();
                      } else if (event.text.unicode == quit_key) {
                          window.close();
                      }
                      break;
                  default:
                      break;
              }
  
              window.clear(sf::Color::Black);
              window.draw(background_sprite);
              window.display();
          }
      }
      return 0;
  }
  </code></pre>